Skip to main content
1 of 4
khollenbeck
  • 389
  • 3
  • 4
  • 16

jQuery, Different way to write multiple click functions?

I have the following .click() functions.

$('.tab').click(function(){
    $('.tab').removeClass('activeTab');
    $(this).addClass('activeTab');
});

$('.edit').click(function(){
    $(this).hide();
    $(this).next().show();
});

$('.cancel').click(function(){
    $(this).parent().hide();
    $(this).parent().prev().show();
});

Is it possible to combine these functions doing something like this?

SUDOCODE:

$.click(function(){
    for $('.tab'){
        //do this
    }
    for $('.edit'){
        //do this
    }
    for $('.cancel'){
        //do this
    }
});

HTML SNIPPET:

<a href="javascript:void(0);" class="edit">Edit</a>
<span class="controls">
    <a href="javascript:void(0);" class="cancel">Cancel</a> |
    <a href="javascript:void(0);" class="save">Save</a> 
</span>
khollenbeck
  • 389
  • 3
  • 4
  • 16