Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the type of the HTML element from a jquery object [duplicate]

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
*/
like image 532
benVG Avatar asked Jan 29 '13 16:01

benVG


1 Answers

$('.myElem').each(function () {
      var htmlType = $(this).prop('tagName') //Example
      console.log(htmlType);
});
like image 141
dimusic Avatar answered Nov 10 '22 15:11

dimusic