Question

I want to hide a block if <li class="first last"> has the text 120V in it.

This is the code i wrote but the block is still showing.

    $(document).ready(function() {
   // check to see if the li tag with css classes .first .last has the text 120V in it 

   if ($(".first .last").text() == "120V"){

   //if true hide the sidebar-second
       $("#my-block").hide();
    }
   else {
   //if false show the sidebar second
        $("#my-block").show();
    }       

    });
});

Where did i go wrong?

Pas de solution correcte

Autres conseils

You need:

$(".first.last").text()

instead of:

$(".first .last").text()

You don't need any space here since space indicate the descendant elements. So your current selector will select any descendant with class last inside any element with class first.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top