Getting Class or Id of element that fired an event

In jQuery we sometimes need to find class or Id of element that fires an event in a web page. This simple code below will do the job for getting Class or Id of element that fired an event in jQuery.

First of all we need jQuery so you need to add self hosted jQuery or one from available CDNs. I’m getting it from Google here.

Next is, we have HTML somewhere in web page:

Getting Class or Id of element that fired an event

And the script we need to attend the Id or class:

 

Like this Post? Share