Zack Lucky
Zack Lucky

Reputation: 671

basic hasClass jquery issue

function buttons(simon, j){
    $(".simon-button").click(function(){
        console.log($(this).hasClass(".simon-button"));
    });
}

Really what to me seemed rather basic, that when a class that has the simon-button class was clicked I wanted it to do some stuff. When I checked the console.log this was returning false? I find this fascinating.

Upvotes: 0

Views: 19

Answers (1)

Akshey Bhat
Akshey Bhat

Reputation: 8545

Remove the . in hasClass function. That's why it's returning false. Your class name is "simon-button" not ".simon-button". ".simon-button" is a selector.

Upvotes: 2

Related Questions