12

Possible Duplicate:
Get element type with jQuery

Preamble: I'm Italian, sorry for my bad English.

From an html code like this:

<input class="myElem" />
<input class="myElem" />
<div class="myElem"></div>
<ul class="myElem"></ul>
<input class="myElem" />

is there a way to retrieve the html objects type?

something like:

$('.myElem').each(function () {
      var htmlType = $(this).type() //Example
      console.log(htmlType);
});

/* Log:
*    input
*    input
*    div
*    ul
*    input
*/
Community
  • 1
  • 1
benVG
  • 603
  • 3
  • 14
  • 25

1 Answers1

35
$('.myElem').each(function () {
      var htmlType = $(this).prop('tagName') //Example
      console.log(htmlType);
});
dimusic
  • 4,123
  • 2
  • 28
  • 31