jquery - Get the selected element's HTML Tag in JavaScript - Stack Overflow

I know you can do this, but every time I Google it I get how to select all elements of a certain tag.So

I know you can do this, but every time I Google it I get how to select all elements of a certain tag.

So, e.g.:

alert($('#my-wrapper').someJSMethod());
{...}
<div id="my-wrapper"></div>

Would alert "DIV" actually. I'm selecting elements with jQuery by the way.

I know you can do this, but every time I Google it I get how to select all elements of a certain tag.

So, e.g.:

alert($('#my-wrapper').someJSMethod());
{...}
<div id="my-wrapper"></div>

Would alert "DIV" actually. I'm selecting elements with jQuery by the way.

Share Improve this question asked Jun 28, 2010 at 23:11 Oscar GodsonOscar Godson 32.8k42 gold badges125 silver badges206 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 9

You can do this:

alert($('#my-wrapper').get(0).nodeName);
//or:
alert($('#my-wrapper')[0].nodeName);

Or, no need for jQuery:

alert(document.getElementById('my-wrapper').nodeName);
$('#my-wrapper')[0].tagName

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745666857a4639173.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信