html - jQuery bind event does not work at all -
i did make happen, without success.
the problem create element on runtime bind function element following code:
$(document).ready(function() { $('.rem').click(function() { $("body").append('<a id="runtime" href="javascript:void(0);">runtime</a>'); }); $('#runtime').bind('click', func_name()); }); //end of doc function func_name() { alert('i got it!'); } in html code have label below:
<div id="body"> <label class="rem">click me</label> </div> my second attempt
$(document).ready(function() { $('.rem').click(function() { $("body").append('<a id="runtime" href="javascript:void(0);">runtime</a>'); }); $('#runtime').bind('click',function() { alert($(this).text()); }); }); //end of doc html code:
<div id="body"> <label class="rem">click me</label> </div>
change
$('#runtime').bind('click',func_name()); to
$('#runtime').live('click',func_name); or (as of jquery 1.7):
$('#runtime').on('click',func_name); two things note:
- i changed
func_name()func_name. don't want call function when bind handler - want reference it. - calling
bindwon't good, because#runtimedoesn't exist until after you've clicked.rem. that's why need eitherliveoron(depending upon jquery version).
and measure: here's reference on why should using jquery.on anyway.
Comments
Post a Comment