Get highlighted HTML tag in JavaScript

I know that you can do this, but every time I go to Google, I get how to select all the elements of a particular tag.

So for example:

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

Actually will warn "DIV". By the way, I select elements with jQuery.

+3
source share
2 answers

You can do it:

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

Or, there is no need for jQuery:

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

Source: https://habr.com/ru/post/1752166/


All Articles