Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

accessing TagName of jquery object

Tags:

jquery

tagname

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?

like image 418
Gaurav Avatar asked Dec 16 '22 23:12

Gaurav


1 Answers

tagName is a property of the underlying DOM element, not an attribute, so you can use prop, which is the jQuery method for accessing/modifying properties:

alert($(obj).prop('tagName'));

Better, however, is to directly access the DOM property:

alert(obj[0].tagName);
like image 111
lonesomeday Avatar answered Feb 15 '23 04:02

lonesomeday