I am trying to create a way to edit a group of comments and identify them by some identifier that I can generate. I have errors that are:
SyntaxError: Failed to execute 'querySelector' for 'Document': '# 1234' is not a valid selector. However, I do not understand how this is possible, since I explicitly have id=1234 in <p> .
In addition, there are problems when, when I comment on everything else and make a warning (id), this does not work for the second form, and the error is that:
Type error: it is impossible to read the 'classList' property with a null value.
Here it is in jfiddle: https://jsfiddle.net/wafqgq0L/2/
document.querySelector('.editable').addEventListener('click', function(event) { var index = event.target.id.indexOf('_'); var id = event.target.id.substring(0,index);
.hidden { display: none; }
//all id will be like 12345_comment <div class="editable"> <p id="1234"> Some comment </p> <form action="form.php" method="post"> <textarea id="1234_editable" class="hidden">Some comment</textarea> <a href="#" id="1234_edit">Edit</a> <a href="#" id="1234_save" class="hidden">Save</a> </form> </div> <br><br> <div class="editable"> <p id="123"> Some comment </p> <form class="editable" action="form.php" method="post"> <textarea id="123_editable" class="hidden">Some comment</textarea> <a href="#" id="123_edit">Edit</a> <a href="#" id="123_save" class="hidden">Save</a> </form> </div>
user4634820
source share