I want to know the tagName of the jquery object , i tried :
var obj = $("<div></div>");
alert($(obj).attr("tagName"));
This alert shows me undefined
. Whats wrong i am doing?
You need to access the underlying DOM node, as jQuery objects don't have a tagName
property, and tagName
is not a property, not an attribute:
var obj = $("<div></div>");
alert(obj[0].tagName);
Notice that I've also removed the call to jQuery on the 2nd line, since obj
is already a jQuery object.
tagName
is a property of the underlying DOM element, not an attribute, so you can useprop
, which is the jQuery method for accessing/modifying properties:Better, however, is to directly access the DOM property: