Когда нажимается "название форума", я хочу, чтобы "subtopic-frame" внутри родительского "forum-themes-head" расширялся. На этой странице есть несколько "forum-themes-head" (со всеми дочерними элементами).
То, как я это делаю сейчас, "forum-themes-head" - это триггер, но я хочу, чтобы "форум-заголовок" был триггером.
HTML:
<div class="forum-topic-head">
<div class="forum-title">Forum Title</div>
<div class="subtopic-frame">
subtopic 1
subtopic 2
</div>
</div>
JQuery:
$(document).ready(function(){
$(".forum-topic-head").click(function(){
$(this).children(".subtopic-frame").slideToggle("slow");
$(this).children(".expand").delay("200").fadeToggle();
});
});
вы можете использовать функцию siblings()
jQuery:
$(document).ready(function(){
$(".forum-title").click(function(){
$(this).siblings(".subtopic-frame").slideToggle("slow");
$(this).siblings(".expand").delay("200").fadeToggle();
});
});
Вы можете использовать this
.closest()
и .find()
для работы только в разделе, которое вы нажимаете в данный момент. Например:
$(".forum-title").click(function() {
$(this).closest(".forum-topic-head").find(".subtopic-frame").slideToggle("slow');
});
скрипка здесь: http://jsfiddle.net/tkcRa/
$(document).ready(function(){
$('.forum-title').on('click',function(){
$(this).parent('.forum-topic-head').children('.subtopic-frame').slideToggle();
});
});