+ 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

10th Dec 2023, 9:31 AM
Web Developer AD
6 Answers
+ 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.
10th Dec 2023, 5:36 PM
Chris Coder
Chris Coder - avatar
+ 2
Thank you Chris Coder I found the mistake and corrected it as you said and it worked. Thank you once again.
11th Dec 2023, 1:04 AM
Web Developer AD
+ 1
Addition to the other answer. It should also be document.getElementsByTagName
10th Dec 2023, 12:20 PM
Toni Isotalo
Toni Isotalo - avatar
+ 1
Thank you to Lisa and Toni Isotalo also.
11th Dec 2023, 1:05 AM
Web Developer AD
0
There is no <p> element. Additionally, you need to wrap all JS in window.onload = () { ... } to prevent loading order issues.
10th Dec 2023, 10:30 AM
Lisa
Lisa - avatar
0
Chris Coder There are no <p> in the first place, so JS won't find any <p> in the first place.
10th Dec 2023, 5:40 PM
Lisa
Lisa - avatar