Jquery: Get Selected Element Tag Name

jQuery: Get selected element tag name

You can call .prop("tagName"). Examples:

jQuery("<a>").prop("tagName"); //==> "A"
jQuery("<h1>").prop("tagName"); //==> "H1"
jQuery("<coolTagName999>").prop("tagName"); //==> "COOLTAGNAME999"

If writing out .prop("tagName") is tedious, you can create a custom function like so:

jQuery.fn.tagName = function() {
return this.prop("tagName");


jQuery("<a>").tagName(); //==> "A"
jQuery("<h1>").tagName(); //==> "H1"
jQuery("<coolTagName999>").tagName(); //==> "COOLTAGNAME999"

Note that tag names are, by convention, returned CAPITALIZED. If you want the returned tag name to be all lowercase, you can edit the custom function like so:

jQuery.fn.tagNameLowerCase = function() {
return this.prop("tagName").toLowerCase();


jQuery("<a>").tagNameLowerCase(); //==> "a"
jQuery("<h1>").tagNameLowerCase(); //==> "h1"
jQuery("<coolTagName999>").tagNameLowerCase(); //==> "cooltagname999"

jQuery tag name of element


this.nodeName instead of $(this).nodeName

this refers to the DOM element itself and $(this) wraps the element up in a jQuery object.


If you require Jquery approach you can use


Need to get TAG name by element name using Jquery

use querySelector() to retrieve the element and tagName to retrieve the tag name


Codepen demo

get tag name using jquery and javascript

You can use .tagName, which is a property of HTMLElement:

var tagNames = []; // Array of tag names
for(var i = 0; i < els.length; i++){

tagName gives you the tag name in caps. You can convert it to small case by using .toLowerCase() on .tagName to get lower cased tag names.

Note :

As an alternative to tagName, you could also use nodeName. For tags, values of tagName and nodeName are identical!

How to get tagname of the current selected element in jquery

Just get the value of a tagName property:

var htmlElementName = this.tagName;

REF: https://developer.mozilla.org/en-US/docs/Web/API/Element.tagName

get selectbox selected value by name tag jquery

Use .val() on select element not on selected option:

$('select[name="country"]').on('change', function(){        alert($(this).val());    });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script><select name="country">        <option value="IND" selected="selected">India</option>        <option value="MY">Malaysia</option>        <option value="US">United states</option>    </select>

How to fetch name from select tag using jquery

If you want to get the attribute name of the select element, remove option:selected from the selector. You can use attr() to get specific attribute:

var getSelect = $('.myclass');console.log(getSelect.attr('name'));
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script><select class="myclass" id="" name="AP"><option value="">Select Val</option>   <option value="50">50</option>   <option value="60">60</option></select>

Getting element by tag name after getting a page using jQuery $.get

I tried using find but that did not work so I ended up using filter and that returned the value of textArea that I needed:

$.get( "/page.html").done(function( data ) {
var textArea = $(data).filter("textarea")[0].innerText;

jQuery get n child value outside of html tag

Replace the content in the span tag and use what remains.

$(function() {
const x = $("#test").text().replace($('#test > span').text(), "");
console.log(Number(x) + Number(x));
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<span id="test">

Get the real clicked element tag name for once with jquery

Use jQuery's stopPropagation() method:

$("*").live('click',function(evt) {

JSFiddle demo.

Related Topics

Leave a reply