Alex
Alex

Reputation: 68396

jquery - check the type of the element

How can I determine what's the type of a element?

For example, I have a function that's hooked on all elements that have a certain class. These elements can be textareas, iframes, divs etc. I want to find out what kind of element is the current one.

Upvotes: 4

Views: 4666

Answers (3)

Bakudan
Bakudan

Reputation: 19482

Here is some working example

HTML:

<span class="some"></span>
<div class="some"></div>

jQuery:

$('.some').each( function ( index ) {
    document.write(index + ':' + $(this).attr("tagName").toLowerCase() + '<br/>');
});

Upvotes: 5

Akram Shahda
Akram Shahda

Reputation: 14771

Use Element Selector to get specific type elements.

And use tagName to get the type of a specific element.

How can I determine the element type of a matched element in jQuery?

Upvotes: 7

neeebzz
neeebzz

Reputation: 11538

You can call attr("tagName"):

$("a").attr("tagName");

Upvotes: 5

Related Questions