Search code examples
jquerytoggleparents

jQuery - trigger toggle on a table element from button in a different table via parents()


I'm trying to toggle (hide/show) a table when clicking a button which is located in a different table, but have trouble selecting it correctly. I intentionnally left id tags out, as I want the jQuery code to be generic because I'll need to reuse it various times in the same script.

here is where I have got so far:

http://jsfiddle.net/Argoron/Dp2sk/24/


Solution

  •  $(document).ready(function() {
    
        $('button.new_disp').toggle(
        function() {
            $(this).closest('table').next('table').hide();
            $(this).text('Show');
        }, function() {
          debugger;
            $(this).closest('table').next('table').show();
            $(this).text('Hide');
        });        
     });