Dave's Brain

Browse - Programming Tips - Using jQuery, how can I find out what kind of tag something is?

Date: 2014jan24
Librarylatform: jQuery
Language: javaScript

Q. Using jQuery, how can I find out what kind of tag something is?
eg checkbox, select, button, etc.

A.  Its not supported directly in jQuery.  You need to use raw DOM:

var tag = $('#mything')[0].tagName.toLowerCase(); alert('mything is a ' + tag);
The [0] converts your query into a DOM object so you can use .tagName. Some browser give it in UPPERCASE so I like to convert it to lower.

Add a comment

Sign in to add a comment
Copyright © 2008-2017, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.