jQuery独立打开每个按钮的内容相同的类
问题描述:
我不认为我的问题是困难的,但我只是一个新手在jQuery和这个论坛,所以希望你能帮助我解决这个问题。我只是想用两个按钮具有相同的类名seperately打开两个div的内容和更容易理解,我会首先显示我的代码片段:jQuery独立打开每个按钮的内容相同的类
<div id="CNN">
<div id="article1">
<div class="content">
My content of CNN goes here
</div>
<div class="more">
My button goes here
</div>
</div>
</div>
<div id="Bloomberg">
<div id="article1">
<div class="content">
My content of bloomberg goes here
</div>
<div class="more">
My button goes here
</div>
</div>
</div>
这里是不工作我目前的jQuery代码:
$(document).ready(function() {
$("div.more").each(function() {
$(this).click(function() {
var target = $(this).parent().next(".content");
$(target).slideDown("slow");
});
});
});
这里我想点击更多的按钮,它只会显示属于它的内容。你可以自由地不遵循我目前的代码:)。所以这就是我的所有问题,希望大家能够帮助我提高编程技能,并且非常感谢您的高级技术!
答
$(document).ready(function() {
$("div.more").click(function(){
$(this).parent().find("div.content").slideDown("slow");
});
});
应该做的伎俩
答
试试这个:
$(document).ready(function() {
$("div.more").click(function() {
var target = $(this).parent().find(".content");
target.slideDown("slow");
});
});
答
试试这个:
$("div.more").click(function() {
$(this).prev().slideDown("slow");
});