Expert Developer JavaScript Question: Download Questions PDF
How do I add a JavaScript event handler to an HTML page element?
![Expert JavaScript Developer Interview Answer Expert JavaScript Developer Interview Question](https://globalguideline.com/public/images/interview/22.png)
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;
<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 Question | Next Question |
What is the role of break and continue statements? | What is encodeURI() function? |