开发者

Get the tag name

Let us say I have in HTML:

<input name="something" id="someid" />

And then in Jquery, I want to click on some element and开发者_开发技巧 after I click I want to get the tag name of the element.

So this.getTheTagName.

Everything I tried so far does not really work, especially for input tag.


You probably mean the name attribute and not the tag name.

alert($('#someid').attr('name'));

If you did mean the tag name, use .prop('tagName'):

alert($('#someid').prop('tagName'));

Here's an example for both: http://jsfiddle.net/wwQ7h/


$('#someid').click( function() {
    alert( this.tagName );
});

Some browsers may not do the click event on input. Instead you might want focus()

$('#someid').focus( function() {
     alert( this.tagName);
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜