I would like to know if there is a way to get the name of a element by its class or id.
for exemple retur
use this:
$('.classTag').get(0).tagName;
or this:
$('.classTag')[0].tagName;
for ex we have this markup:
<div class=classTag>my div </div>
var $tag = $('.classTag')[0].tagName; //this will return 'DIV'as result
alert($tag);
Try tagName
:
var input = document.getElementsByClassName("some-class")[0];
alert(input.tagName);
JSFiddle: http://jsfiddle.net/PG656/1/
Actually $('.some-class')
returns an array of elements with this class, so you have to loop through it:
$('.some-class').each(function(){
console.log(this.nodeName);
});
this will output their node names to console
you can use:
var input = document.getElementsByClassName("some-class")[0]
alert(input.type);
alert(input.name);
var tagName = $('.some-class').prop('tagName');
the name of the tag will be returned in capital letters