jquery:从类选择器中获取id [英] jquery: get id from class selector

查看:155
本文介绍了jquery:从类选择器中获取id的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨Stackoverflow社区,



很难解释,但... ...

有没有什么办法可以让我可以从类似于

 < a href =#class =testid = test_1>某些文字< / a> 
< a href =#class =testid =test_2>一些文字< / a>
< a href =#class =testid =test_3>有些文字< / a>

然后我绑定


$('。test')


所以当我点击其中一个元素时, / p>

让我知道是否需要进一步解释。



非常感谢高级版本。

解决方案

Doh ..如果我找对了,它应该是这样简单的:

<$点击(函数(){
alert(this.id);
});

您可以访问 id属性在事件处理程序中的底层 DOM节点上。


Hi Stackoverflow Community,

hard to explain but...

is there any way that I can get the id of an element from something like

<a href="#" class="test" id="test_1">Some text</a>
<a href="#" class="test" id="test_2">Some text</a>
<a href="#" class="test" id="test_3">Some text</a>

and then I bind

$('.test')

so when I click one of the elements I get back the id?

Let me know if I need to explain further.

Thanks a lot in advanced.

解决方案

Doh.. If I get you right, it should be as simple as:

$('.test').click(function() {
    alert( this.id );
});

You can just access the id property over the underlaying dom node, within the event handler.

这篇关于jquery:从类选择器中获取id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆