<li class="abc">
<div attribute="xyz">stuff</div>
</li>
如果我具备以上条件。我想隐藏
<li class="abc">
标签和子标签(如果是子标签)
<div atribute="xyz">
存在。
谢谢。
答案 0 :(得分:1)
您错过了jQuery DOM,请检查并尝试。
$(function(){
$("div[someattribute='xyz']").parent().hide();
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul>
<li class="abc">this needs to go away
<div someattribute="xyz">hello</div>
</li>
<li>This doesn't either</li>
<li>This does, but whatever.</li>
<li>And I was like, "whatever dude".</li>
<li>This doesn't have our text, once again</li>
</ul>
答案 1 :(得分:1)
这是一个原型答案(也许与您的尝试有关)
function doIt() {
$$('[someattribute=xyz]').each(function(e){ e.up('li').hide(); });
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/prototype/1.7.3/prototype.js"></script>
<ul>
<li class="abc">this needs to go away
<div someattribute="xyz">hello</div>
</li>
<li>This doesn't either</li>
<li class="abc">this needs to go away aswell
<div class="ohMyGodAWrapper">
<div someattribute="xyz">hello</div>
</div>
</li>
<li>This does, but whatever.</li>
<li>And I was like, "whatever dude".</li>
<li>This doesn't have our text, once again</li>
</ul>
<button id="go" onclick="javascript: doIt();">Click Me!</button>