Expert Developer JavaScript Question:
Download Questions PDF

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

Expert JavaScript Developer Interview Question
Expert JavaScript Developer Interview Question

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 Interview Questions And Answers PDF

Previous QuestionNext Question
What is the role of break and continue statements?What is encodeURI() function?