how Add click event on div tag using javascript

 

Questions


I have a div tag in my form without id property.
I need to set on-click event on this div tag.

Html

<div class="drill_cursor" >
....
</div>

Can any one tell me how can a add a on-click event on this tag using java-script.
Not:- I don’t want to use id property of div tag.

 

 

————————————————-

Answer

If you are using javascript only, please

document.getElementsByClassName('drill_cursor')[0]
        .addEventListener('click', function (event) {
            // do something
        });

it is simple with jquery

$(".drill_cursor").click(function(){
//do something
});

html,javascript

Facebook Comments

Post a comment