0

How to get the id or class of any element that is clicked using Jquery?I don't know the ID of the element i want asynchronouly clicked element ID.

Vishal Patil
  • 381
  • 3
  • 15

2 Answers2

0
$(document).on('click',function() {
 var classes = $(this).attr('class');
 var id = $(this).attr('id');
});

This is for any click done on the page, for an specific element:

 $("#elem_id").on('click',function(){
     var classes = $(this).attr('class');
     var id = $(this).attr('id');});
jonystorm
  • 548
  • 4
  • 17
0

In Html

You can do various logic on its click event as

 $('#idget').click(function(){
     ....//logic
    });

Or

  $('.customclass').click(function(){
      ....//logic
    });
DAre G
  • 177
  • 10