如果<li class="first last">中有文本120V,我想隐藏一个块。
这是我写的代码,但代码块仍然显示。
$(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();
}
});
});我哪里错了?
发布于 2014-03-01 01:29:30
您需要:
$(".first.last").text()而不是:
$(".first .last").text()这里不需要任何空格,因为空格表示后代元素。因此,您当前的选择器将选择任何具有类first的元素中具有类last的任何子代。
https://stackoverflow.com/questions/22101904
复制相似问题