admin管理员组

文章数量:1435859

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

本文标签: jqueryGet the selected element39s HTML Tag in JavaScriptStack Overflow