jquery - dynamic button not firing -
i using jquery generate bit of html includes button. reason, can't button event fire generated button.
the generated html looks fine when view source...i looked through firebug , don't see wrong....the button click event not being fired dynamically generated button.
any appreciated.
here code:
$(document).ready(function () { $("#btnsearch).click(function () { var html = ""; html += "<tr><td>test</td></tr>"; html += "<tr><td>test 2</td></tr>"; html += "<tr><td><input id="btntest" type="button" value="test button" /></td></tr>"; $(html).appendto("#testtable"); }); $("#btntest").on("click", function () { alert('hey'); }); });
my static html simply:
<table id="testtable"></table>
$('body').on('click', '#btntest' function () { alert('hey'); });
you need read .on
documentation , understand it's doing better. it's different old .live
method.
Comments
Post a Comment