gpt4 book ai didi

javascript - 查找并循环(this)JQuery 内的 span 元素?

转载 作者:行者123 更新时间:2023-11-28 16:15:26 25 4
gpt4 key购买 nike

我试图找到每一个<span class ="anime_yellow">..在另一个里面<span class="toggle"> ,这是代码:

HTML:

    <span class="title_white">Menu 1</span>
<span class="toggle">
this is menu 1 i want to animate
<span id="position" class="anime_yellow">Position</span>
and
<span id ="market" class="anime_yellow">market</span>.
</span>
<br><br>

<span class="title_white">Menu 2</span>
<span class="toggle">
this is menu 2 i want to animate
<span id="simple" class="anime_yellow">Simple</span>
and
<span id ="kool" class="anime_yellow">Kool</span>.
</span>

Javascript:

$(".toggle").hide();
$(".title_white").click(function() {
$(".toggle").hide();
$(this).next(".toggle").toggle("slow");
// i want to find every span.anime_yellow inside the
// THIS TOGGLE class and get its element ID
// and then run function on the ID
// animate(position) or animate(simple).

});

我正在尝试使用jquery函数.find(),但不知道从哪里开始,这是它的jsfiddle:http://jsfiddle.net/wJJBa/2/

最佳答案

你的意思是你想这样做:http://jsfiddle.net/sZUAE/1/

function animate(divID) {
alert(divID);
}

$(".toggle").hide();
$(".title_white").click(function() {
$(".toggle").hide();
var $toggle = $(this).next(".toggle");
$toggle.toggle("slow");
$toggle.find(".anime_yellow").each(function(i, e) {
animate(e.id);
});
});

关于javascript - 查找并循环(this)JQuery 内的 span 元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11633080/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com