Javascript/jQuery - How do I obtain name of the class of clicked element?

Viewed 53143

I googled and googled and I concluded that it's very hard to get answer on my own.

I am trying to use jquery or JavaScript to get a property of clicked element. I can use "this.hash" for example - it returns hash value I presume.

Now I would like to get name of the class of clicked element. Is it even possible? How? And where would I find this kind of information?

  • jQuery documentation? - All I can find is methods and plugins, no properties.. if its there - please provide me with link.

  • JavaScript documentation? - is there even one comprehensive one? again please a link.

  • DOM documentation? - the one on W3C or where (link appreciated).

And what is this.hash? - DOM JavaScript or jQuery?

6 Answers

There's a way to do this without coding. Just open the console of your browser (f12?) and go to element you want. After that, hover or click the item you want to track.

Every change done on the DOM will be for a few seconds marked (or lightened) as another color on the console. (Watch the screen capture)

On the example, each time I hover a "colorItem", the 'div' parent and the "colorItem" class appears lightened. So in this case the clicked class will be 'swiper-model-watch' or 'swiper-container' (class of the lightened div)

obtain name class clicked

Related