我需要能够单击一个 div,显示其中的文本,然后当单击另一个 div 时,隐藏其他 div 中的所有其他文本并显示单击的 div 中的文本。
代码在这里
http://jsfiddle.net/Refxq/140/
<div class="myClass"><span>First</span></div>
<div class="myClass"><span>Second</span></div>
<div class="myClass"><span>Third</span></div>
.myClass{
height:50px;
width:100%;
background-color:red;
margin:2px;
}
.myClass span{
display:none;
}
$(".myClass").click(function() {
// Hide all item spans
$(".myClass span").hide();
// Show the element next to this
$(this).first().show();
});
最佳答案
这将起作用:See fiddle
$(".myClass").click(function() {
// Hide all item spans
$(".myClass span").hide();
// Show the element next to this
$(this).find('span').show();
});
关于jquery - 显示刚刚单击的元素的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22556772/