Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (13.1k points)
Can anyone help me with what is the difference between jQuery.click() vs onclick methods? Which is better?

1 Answer

0 votes
by (26.7k points)

Basically, the click() function is better as it is based on the standard event registration model. Also, you can add more than one event listener to any target and you can call addEventListener() for that particular target.

var myEl = document.getElementById('myelement');

myEl.addEventListener('click', function() {

    alert('Hello world');

}, false);

myEl.addEventListener('click', function() {

    alert('Hello world again!!!');

}, false);

I hope this will help.

Want to become a Java Expert? Join Java Training now!!

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Apr 7, 2021 in Java by dante07 (13.1k points)
0 votes
1 answer
0 votes
1 answer

Browse Categories

...