How to verify the existence of the class in this case of jQuery?

Asked

Viewed 451 times

1

How can I check if the class exists in a variável jQuery?

jQuery(function($) {

    // Captura o atributo para manipulá-lo
    var atributo = jQuery(this).parent('.servico').children('.servicos_the_content');

I tried it but it didn’t work:

if($(atributo)).hasClass('active'){

     // faz alguma coisa

}
  • 1

    Your condition is wrong, the if ends here: if($(atributo)). Switch to if($(atributo).hasClass('active')) and be happy :)

1 answer

2


Notice you have an error in logic and parenthesis:

if($(atributo)).hasClass('active'){

must be

if(atributo.hasClass('active')){

In this case atributo is already a jQuery object.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.