javascript - Html element can not be addressed after jquery .html -
this question has reply here:
event binding on dynamically created elements? 13 answersi seek insert button .html(...) , should execute code. doesn´t work, button (inserted .html(...)) doesn´t response after clicking him.. have no thought can do, asked google help, found nothing.. hope can help me :)
here html:
<html> <head> <title>multiplie files</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <script src="js/libs/jquery/jquery.js"></script> <script type="text/javascript" src="js/files.js"></script> </head> <body> <button id="button">test</button> <div id="field"></div> </body> and here javascript:
$('document').ready(function() { $('#click').click(function() { alert(true); }); $('#button').click(function(){ $('#field').html('<input value="click" type="button" id="click"/>'); //document.getelementbyid("field").innerhtml = '<input value="click" type="button" id="click"/>'; }); });
i tried jquery .html , normal javascript .innerhtml.. nil works..
thanks every reply! :)
try utilize event-delegation on dynamically created elements,
$('#field').on('click','#click',function() { alert(true); }); javascript jquery html web
No comments:
Post a Comment