I want to hide any visible span elements if any is visible, and toggle it again if a element is clicked
<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();
}
});
live example http://jsfiddle.net/BGSyS/
the issue is when I click for example 'element 1
' 'span1
' is still visible and I want to toggle this
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…