Jordan
Jordan

Reputation: 31

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 {
        //nothing 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!

Upvotes: 2

Views: 231

Answers (1)

James Hill
James Hill

Reputation: 61832

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!");
    }
});

Upvotes: 3

Related Questions