【发布时间】:2013-01-29 03:49:30
【问题描述】:
我在选择 jQuery 中的第一个孩子时遇到了一些麻烦。我试图这样做是为了避免有很多 if 语句。基本上,您单击一个按钮。此类选择器设置为处理我的 JS 中的点击。进入 JS 后,我想获取刚刚单击的项目的子项,但我没有任何乐趣。
这是我的 JS 中的内容:
$('.itemClicked').click(function(){
var id = $(this).attr('id').first();
// it can't find the method first() here. If I just find the id, I get the
// correct ID of what I just clicked.
var test = id.first();
// I tried the above to seperate the ID from the first() method request
// no joy with this either.
test.toggleClass("icon-tick");
// this is my ultimate aim, to toggle this icon-tick class on the item
// clicked.
});
如果您能在这里帮助我,请提前致谢。我可能只是在做一些愚蠢的事情,但我很难意识到那是什么。
【问题讨论】:
标签: javascript jquery css-selectors