How-To: Find tag name in jQuery

jQuery’s .attr() function makes it simple to find every attribute of a tag. ┬áBut what about the tag name?

Turns out, it’s just as easy:


update: This is a JavaScript function associated with a click event. You cannot access the tagName from a selector.

update 2: you can get the tag name in a loop like this:


update 3: Here’s a way to check if the element matches a type. This doesn’t actually return the element type, it is just a way to check if it matches a tag name. This method returns true or false.


This will also work inside a click listener method:


One thought on “How-To: Find tag name in jQuery

Leave a Reply

Your email address will not be published. Required fields are marked *