How can I improve this click/toggle function in jquery?
$('.tabs a ').click(function () {
var a = $(this).attr('href');
if (a == '#tab-1') {
$('.btn-buy').hide();
$('.btn-sell').show();
} else {
$('.btn-sell').hide();
$('.btn-buy').show();
}
return false;
});
... it works, but the code is ug开发者_如何学编程ly, too many lines. Can it be reduced any further?
Thanks in advance for your help!
You could just use toggle:
$(".tabs a").click(function() {
$(".btn-buy").toggle();
$(".btn-sell").toggle();
});
This would assume they start out in their correct state initially...
精彩评论