【问题标题】:How to affect only a first next specific div如何只影响第一个下一个特定的 div
【发布时间】:2017-01-06 10:38:37
【问题描述】:
<div class='images'></div>
<div class='toload'></div>
<div class='sky'></div>
<select class="select01">
    <option value="winners_02/2015.php">2015 - DOPS 6</option>
    <option value="winners_02/2014.php">2014 - DOPS 5</option>
    <option value="winners_02/2013.php">2013 - DOPS 4</option>
</select>

<div class='images'></div>
<div class='sea'></div>
<div class='toload'></div>  // target

JS

$('.select01').change(function(){
    var a = $(this).val();
    //something like: next().first(`toload`).load(a);
});

我在每个select01之前和之后都有各种情况。
更改 select01 我只需要影响名为 toload 的第一个下一个 div。
在上面的例子中,它被标记为target

【问题讨论】:

标签: jquery


【解决方案1】:

您可以使用nextAll() 并只匹配第一个:

$(this).nextAll('.toload').first().load(a);

如果没有其他在您的特定情况下不喜欢.toLoad 特定点击的兄弟.select01,然后使用:

$(this).siblings('.toload').load(a);

【讨论】:

  • 在他的标记中有 2 个元素的类 toload 一个在我认为你需要使用 .next() 之后选择另一个,因为他想要下一个。 OP 说first next div named toload
  • @guradio 是的,谢谢!我错过了,但仍然保留第二个例子,它仍然规定if there is no other .toLoad sibling
猜你喜欢
  • 2022-12-06
  • 2015-12-29
  • 2021-12-30
  • 2013-05-29
  • 2016-12-24
  • 2013-02-02
  • 2023-04-01
  • 1970-01-01
  • 2022-10-19
相关资源
最近更新 更多