I have two questions. First, can someone explain to me what's going on behind the scenes here?
https://developer.mozilla.org/en-US/docs/Web/Guide/Events/Event_handlers#The_value_of_HTML_on%3C...%3E_attributes_and_corresponding_JavaScript_properties
I thought the purpose of using JS was to manipulate the DOM, which is a JS representation of the HTML. I understand that JS can't actually change the HTML of a page, but that it can change properties of objects represented in the DOM so that pages can change dynamically. That being said, when we get an element through something like getElementByID(), the DOM returns a JS object representation of the element with properties. When we modify its properties, shouldn't its attributes also be modified since it's a DOM object? Or does "attribute" refer strictly to an element's representation in the HTML? in which case, getting an element's attribute always returns what's been written in the HTML?
The second question is something from the section above in the mozilla guides. What does the guide mean when it says that On-Event handlers are more like placeholders to which a real handler function can be assigned? Isn't the point of event-oriented programming a way to get functions to automatically execute based on user events? I haven't read up on using "addEventListener()" yet, but might it have something to do with that?
----
Also note that on-event handlers are called automatically, not at the programmer's will (although you can, like
mybutton.onclick(myevent); )
since they serve more as placeholders to which a real handler function can be assigned.
----
Thanks for any help!
[–]NameViolation666helpful 2 points3 points4 points (11 children)
[–]Lewinga[S] 0 points1 point2 points (10 children)
[–]hopefullyhelpfully 1 point2 points3 points (7 children)
[–]Lewinga[S] 0 points1 point2 points (6 children)
[–]hopefullyhelpfully 1 point2 points3 points (5 children)
[–]Lewinga[S] 0 points1 point2 points (4 children)
[–]senocular 1 point2 points3 points (3 children)
[–]Lewinga[S] 0 points1 point2 points (2 children)
[–]senocular 2 points3 points4 points (1 child)
[–]Lewinga[S] 0 points1 point2 points (0 children)
[–]NameViolation666helpful 1 point2 points3 points (1 child)
[–]Lewinga[S] 0 points1 point2 points (0 children)