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

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


Just one jQuery too much:

$("[id$=" + endOfIdToMatch + "]").each(function () {    alert(this.tagName);});


Consider this solution without using each():

var elements = $("[id$=" + endOfIdToMatch + "]");var vals = elements.is("input").val();var htmls = elements.is("label").html();var contents = vals.concat(htmls);

Have a look at the documentation for is.


you could also use something like this:

if ($(this).is('input:checkbox'))

replace "this" with whatever instance you need and 'checkbox' with whatever input type you need.