这是html结构:
<span id="17">yes here</span>
<div class="PricevariantModification vm-nodisplay"></div>
<div class="PricesalesPrice vm-display vm-price-value">
<span class="a"></span>
<span class="b"></span>
<div>
我需要使用第一个跨度
选择具有“b”类的span标记任何人都知道,请给我正确答案。
答案 0 :(得分:2)
我需要使用
您可以使用横向方法:
$('#17').nextAll('.PricesalesPrice:first').find('.b')
答案 1 :(得分:0)
使用以下js代码寻求帮助
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<span id="17">yes here</span>
<div class="PricevariantModification vm-nodisplay"></div>
<div class="PricesalesPrice vm-display vm-price-value">
<span class="a"></span>
<span class="b">hello</span>
<div>
&#13;
{{1}}&#13;
答案 2 :(得分:0)
你可以使用css next cibling Adjacent sibling selectors
span.a + span.b{ color:red }
<span id="17">yes here</span>
<div class="PricevariantModification vm-nodisplay"></div>
<div class="PricesalesPrice vm-display vm-price-value">
<span class="a">Span a</span>
<span class="b">Span b</span>
<div>
但结果与
相同
span.b{ color:red }
<span id="17">yes here</span>
<div class="PricevariantModification vm-nodisplay"></div>
<div class="PricesalesPrice vm-display vm-price-value">
<span class="a">Span a</span>
<span class="b">Span b</span>
<div>
$("span.a").next("span.b").css( "color", "red" );
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<span id="17">yes here</span>
<div class="PricevariantModification vm-nodisplay"></div>
<div class="PricesalesPrice vm-display vm-price-value">
<span class="a">Span a</span>
<span class="b">Span b</span>
<div>