开发者

jQuery Multiple Conditionals Help

I'm trying to make an event listener for when a button is 'active' (has an .active class in my case) and a link is clicked, an event happens. But I'm having trouble chaining the two conditionals together and it doesn't seem to work.

    if($('.talk').hasClass('active') && $('.goblin').click()){
        alert("the world has gone mad!");
    } else {
        //n开发者_如何学Pythonothing happens
    } 

The code is above. Again, the two conditions are:

*The 'Talk' button is active

*The link with class 'Goblin' is clicked

I'm thinking I'll have to use .live() or something for this, but I'm not sure. Help!


You should bind to the click event of Goblin, then check for your active condition:

$('.goblin').click(function () {
    if($('.talk').hasClass('active'))
    {
        alert("the world has gone mad!");
    }
});
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜