如何影响 jQuery 中具有特定后代的祖先?
我有这两个具有相同类名 () 的 DIV:
<div class="myOutterDiv">
<ul class="innerUL">
<li id="num1">1</li>
<li id="num2">2</li>
</ul>
</div>
<div class="myOutterDiv">
<ul class="innerUL2">
<li id="letterA">A</li>
<li id="letterB">B</li>
</ul>
</div>
我想将带有蓝色边框的 css 边框应用于包含 2 的边框,将红色边框应用于包含 B 的边框。
我尝试过使用parentsUntil (),但对 class="myOutterDiv" 之前的所有祖先应用了边框。我只想影响 class="myOutterDiv"。
谢谢!
I've got these two DIVs which have the same class name ():
<div class="myOutterDiv">
<ul class="innerUL">
<li id="num1">1</li>
<li id="num2">2</li>
</ul>
</div>
<div class="myOutterDiv">
<ul class="innerUL2">
<li id="letterA">A</li>
<li id="letterB">B</li>
</ul>
</div>
I'd like to apply a css border with a blue color to the one that contains 2
and red to the one that contains B
.
I've tried using parentsUntil(), but applied a border to all the ancestors up to class="myOutterDiv". I just want to affect class="myOutterDiv".
Thanks!
这对你有用吗?
Would this work for you?