我有一个小的jQuery问题:
我的代码如下:
<div id="select-word-5" class="select-word-link"> - some content - </div>
<div id="select-5" class="select"> - some content - </div>
我在文档中有几个选择词链接和选择div。
我想在第一个div上添加一个点击事件,只对第二个div做出反应。
我的想法是循环遍历所有的“select-x”元素,但我认为还有更好的方法吗?
$('.select-word-link').each(function()
{
var id = this.id;
var idLink = this.id.replace("-word", "");
$('.select').each(function()
{
if (idLink == this.id)
{
$(id).click(function() {
alert("this does not work");
});
});
});