Bluefire Bluefire - 2 years ago 110
HTML Question

How to get an element's ID from

Consider a piece of code that looks like the following:

$('body').on('click', function(e){


I know there is a way to get the element type from
, i.e.
, but how can I get the id of that element from that? If that can't be done, is there another way to get the id of the element that was clicked on?

Answer Source

You can use represents DOM object and you can access all its property and methods.

$('body').on('click', function(e){

You can convert the DOM object to jQuery object using jQuery function jQuery( or $( to call the jQuery functions on it.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download