使用jquery在另一个元素的兄弟中找到一个元素

时间:2015-11-30 10:28:42

标签: jquery

<div class="container">
    <input type="button" value="play" class="btnplay"></input>
    <audio class="song">
        <source src="<%# Eval("f_audio") %>" />
    </audio>
    <div class="progress-show">
        <span class=".currTime">dsgbadgnsetb</span>
        <input class="progress-slider mdl-slider mdl-js-slider" type="range" min="0" max="100" value="0" tabindex="0">
        <span class=".totalTime">sfhsg s</span>
        <input class="volume-slider mdl-slider mdl-js-slider" type="range" min="0" max="100" value="50" tabindex="0">
    </div>
</div>

我想找到一个带有currTime类的span标签,并改变它的值,但通过这样的btnplay:

$('.btnplay').click(function () {
    $(this).siblings('.progress-show').next('.currTime').text('111111');
});

但它不起作用,正确的语法是什么?

3 个答案:

答案 0 :(得分:1)

使用.find()代替.next()因为.currTime是子元素而不是.progress-show的下一个兄弟:

$('.btnplay').click(function () {
    $(this).siblings('.progress-show').find('.currTime').text('111111');
});

答案 1 :(得分:1)

更改您的HTML并将CSS类重命名为currTime而不是.currTime,否则您需要将.作为元字符转义

HTML更改

<span class="currTime">dsgbadgnsetb</span>

然后使用,children()应该用于获取子元素。

$('.btnplay').click(function () {
    $(this).siblings('.progress-show').children('.currTime').text('111111');
});

使用现有HTML,使用.

转义元字符\\
$('.btnplay').click(function () {
    $(this).siblings('.progress-show').children('.\\.currTime').text('111111');
});

答案 2 :(得分:0)

.next()会获取<audio>元素。你必须尝试找到像:

这样的元素
jQuery(".btnplay").click(function() {
    jQuery(this).siblings(".progress-show").find(".currTime").text("Some Text");
});

jQuery.next()jQuery.find()

的文档
相关问题