调用click函数方法,但如果它有另一个类关联则不会

时间:2011-03-03 19:50:11

标签: javascript jquery

我有以下代码:

 $('#commentContainer').delegate('div.comment-vote div.vote', 'click', function () {

//etc
}

我希望这个被调用但是当div.vote还有一个类“unauthenticated”时

我该怎么做?

<div class="vote"></div>//this one when clicked call click function in delegate

<div class="vote unauthenticated"></div>//this one do nothing.

1 个答案:

答案 0 :(得分:1)

使用not-selector[docs]

$('#commentContainer').delegate('div.comment-vote div.vote:not(.unauthenticated)', 'click', function () {

现在,click事件将仅在具有div.vote类的unauthenticated元素上触发处理程序。