+ 1
Please help me!
I made a notes app. I want to know that why the JavaScript's document.getElementByTagName is not working? It is in line 17 of javascript code. Here is the code:- https://sololearn.com/compiler-playground/WovfcT5q7ELF/?ref=app
6 odpowiedzi
+ 2
Arjun Dawande
The <p> elements are created when we use appendChild(newNote).
As Toni mentioned, getElement should be corrected to getElements. This seems to be the main issue.
Judging by the error. There may be an issue with directly assigning the onclick event without wrapping it in a function. If you were to use this, it would look like the following:
p.onclick = function() {
alert("This is a note.");
};
An extra tip is
Since newNote is already created as a variable for the newly generated <p> element, there's no need to create a separate variable p. Instead, assign the onclick handler directly to newNote:
newNote.onclick = function() {
alert("This is a note.");
};
You can place the example after line 11.
For it all to work be sure to remove lines 17 and 18
With these edits I was able to achieve what I think is a better result and solution to the problem. Please let me know if there are anymore errors, or questions.
+ 2
Thank you Chris Coder I found the mistake and corrected it as you said and it worked. Thank you once again.
+ 1
Addition to the other answer.
It should also be document.getElementsByTagName
+ 1
Thank you to Lisa and Toni Isotalo also.
0
There is no <p> element.
Additionally, you need to wrap all JS in
window.onload = () {
...
}
to prevent loading order issues.
0
Chris Coder There are no <p> in the first place, so JS won't find any <p> in the first place.