show hide on click using on

show hide on click using on

I am having problems with toggle()  called inside on

here is my script

  1. function tblBodyShowHide(){
  2. $(document).on('click','a.showHideTblRows',function (event){
  3. var tbody = $(this).closest('table').find("tbody");
  4. var thead = $(this).closest('table').find("thead");
  5. if(thead!=null){
  6. thead.toggle();
  7. }
  8. tbody.toggle();
  9. //event.preventDefault();
  10. return; 
  11. });
  12. }
  13. $(document).ready(function(){
  14.  tblBodyShowHide();
  15. }

is there anything wrong in the function?   on debug I see  table   body is   hidden and when the method is returned tbody shows up again.