Can someone please tell me what is the difference betweenthese two approaches, w
ID: 3611571 • Letter: C
Question
Can someone please tell me what is the difference betweenthese two approaches, which look the same to me: <a href="#" id="myLink" and <a href="#" id="myLink">my link</a> <script> document.getElementById('myLink').onclick=handleMyClick </script> (assuming that the handleMyClick function is specified in the<head> section of the page). Thank you. Can someone please tell me what is the difference betweenthese two approaches, which look the same to me: <a href="#" id="myLink" and <a href="#" id="myLink">my link</a> <script> document.getElementById('myLink').onclick=handleMyClick </script> (assuming that the handleMyClick function is specified in the<head> section of the page). Thank you. <a href="#" id="myLink">my link</a> <script> document.getElementById('myLink').onclick=handleMyClick </script> (assuming that the handleMyClick function is specified in the<head> section of the page). Thank you.Explanation / Answer
Both the approaches results the same. They are almost similarbut,
The getElementById() method returns a reference to the elementwith the specified ID
If there is no element with the given id, this function returnsnull.
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.