我想隐藏任何可见的跨度元素(如果有的话),如果单击一个元素,我想再次切换它
<div class="item">
<a href="">element1</a> <span>span1</span>
<br>
</div>
<div class="item">
<a href="">element2</a> <span>span2</span>
<br>
</div>
<div class="item">
<a href="">element3</a> <span>span3</span>
<br>
</div>
<div class="item">
<a href="">element4</a> <span>span4</span>
<br>
</div>
JS
$('.item span').hide();
var all_spans = $('.item a').parent().find('span');
$('.item a').click(function(e) {
e.preventDefault();
// hide all span
all_spans.hide();
$this = $(this).parent().find('span');
// here is what I want to do
if ($this.is(':hidden')) {
$(this).parent().find('span').show();
} else {
$(this).parent().find('span').hide();
}
});
现场示例http://jsfiddle.net/BGSyS/
问题是当我单击例如' element 1
'' span1
'仍然可见并且我想切换它时