4

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.

Alex
  • 66,732
  • 177
  • 439
  • 641

3 Answers3

7

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?

Community
  • 1
  • 1
Akram Shahda
  • 14,655
  • 4
  • 45
  • 65
5

You can call attr("tagName"):

$("a").attr("tagName");
neebz
  • 11,465
  • 7
  • 47
  • 64
5

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/>');
});
Bakudan
  • 19,134
  • 9
  • 53
  • 73