如果我试图将文本放入下面的一个投票标签元素中,我将如何在jquery中引用它?
<ul class="round round-1">
<li class="spacer"> </li>
<li class="game game-top pair1">
<span class="left-rail">
<span class="seed">1</span>
<span class="vote-tally"></span>
</span>
<span class="right-rail">
<span class="lead-img"><img src="img/myimage.jpg"></span>
<span class="name-text">First guy</span>
</span>
</li>
<li class="game game-bottom pair1">
<span class="left-rail">
<span class="seed">16</span>
<span class="vote-tally"></span>
</span>
<span class="right-rail">
<span class="lead-img"><img src="img/anotherimg.jpg"></span>
<span class="name-text">Second guy</span>
</span>
</li>
</ul>
jquery的:
$('.round-1').find('.game-top .pair1').find('.left-rail').find('.vote-tally').text('5'); //doesn't work
答案 0 :(得分:1)
你这个级别的选择器应该是chaind:
.find('.game-top.pair1')
或者像这样:
$('.round-1').find('.game-top.pair1 .left-rail .vote-tally').text('5');
答案 1 :(得分:0)
您可以在jQuery中使用子选择器,如下所示:
var elem = $(".round-1 > .game-top.pair1 > .left-rail > .vote-tally");
elem.text("5");