javascript - how to add onclick events to dynamically generated buttons and show /hide the table -
i have many buttons generating dynamically based on end user request
$out='<input class="show_hide" type="button" id="'.$platform_name.'" value="'.$platform_name.'"/>';
the same variable name tables coming dynamically
$out.='<table id="'.$platform_name.'" > </table>
if suppose button
<input class="show_hide" type="button" id="button1'" value="button1"/> <table id="button1" > </table>
how number of button names/id, , based on button name/id finding table , show/ hide table. please me. fresher in php
when comes dynamic binding, go delegates
$( "body" ).on( "click", ".show_hide", function() { $( ).next().toggle(); });
or can provide selector in sibling selection
$( "body" ).on( "click", ".show_hide", function() { $( ).next("#table1").toggle(); });
this code hide/show next sibling(in case table) on button click class show_hide
Comments
Post a Comment