show hide on click using on
I am having problems with toggle() called inside on
here is my script
- function tblBodyShowHide(){
- $(document).on('click','a.showHideTblRows',function (event){
- var tbody = $(this).closest('table').find("tbody");
- var thead = $(this).closest('table').find("thead");
- if(thead!=null){
- thead.toggle();
- }
- tbody.toggle();
- //event.preventDefault();
- return;
- });
- }
- $(document).ready(function(){
- tblBodyShowHide();
- }
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.