Refactoring Tabs

Posted by Nimbuz on Stack Overflow See other posts from Stack Overflow or by Nimbuz
Published on 2010-06-14T17:38:39Z Indexed on 2010/06/14 18:02 UTC
Read the original article Hit count: 225

Filed under:
|
|

HTML:

<ul>
    <li><a href="#tab1">tab1</a></li>
    <li><a href="#tab2">tab2</a></li>
</ul>
<div id="tab1" class="tab-content">content 1</div>
<div id="tab2" class="tab-content">content 2</div>

jQuery

$('#mode li:first').addClass('active');
$('#mode li.active').append('<span class="arrow">&nbsp;</span>');
$('#mode li a').click(function () {
    $('#mode li').removeClass('active')
    $('.arrow').remove();
    $(this).parent().addClass('active').append('<span class="arrow">&nbsp;</span>');
    var a = $(this).attr('href');
    $('.tab-content').hide();
    $(a).show();
    return false;
});

.. works, but looking ugly. Can it be simplified/reduced further?

Many thanks!

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about refactoring