Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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.