I've written a simple accordion using zepto js lib.
Looking for advice on how to improve this better.
HTML
<div class="box">
<span class="learn-more"><a href="#">Learn more</a></span>
<div class="more">
blah<br>
blah<br>
blah<br>
<span class="close"><a href="#">close</a></span>
</div>
</div>
<div class="box">
<span class="learn-more"><a href="#">Learn more</a></span>
<div class="more">
blah<br>
blah<br>
blah<br>
<span class="close"><a href="#">close</a></span>
</div>
</div>
Javascript
$('.more').addClass('hide');
var learnMore = $('.learn-more'),
close = $('.close');
learnMore.click(function() {
$(this).hide().next('div').toggleClass('hide');
});
close.click(function() {
$(this).parent().toggleClass('hide');
$(this).parent().prev().show();
});
Working demo
How can I prevent the page from jumping when I click on the empty anchor tags?
$('.box .learn-more a, .box .close a').click(function(e){e.preventDefault();});– andho Nov 29 '12 at 4:01