Expert Developer JavaScript Question: Download Expert JavaScript Developer PDF

How do I add a JavaScript event handler to an HTML page element?

Tweet Share WhatsApp

Answer:

You can use inline event handlers to add a JavaScript handler to an HTML page element. The disadvantage of this technique is that it allows you to have one handler per element. There are different browsers which allow you to have dynamic handler added to the HTML page element. Example of inline event handler is given below:
<a href="ineh.htm" onlick="alert('Hello!')">Good Morning!</a>
// event handlers added by assignment (usually right after the page loads), e.g.:
document.onclick=clickHandler;
document.onkeydown=keyHandler;

Download Expert JavaScript Developer PDF Read All 150 Expert JavaScript Developer Questions
Previous QuestionNext Question
What is the role of break and continue statements?What is encodeURI() function?