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?

没有正确的解决方案

其他提示

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top