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:

  1. i changed func_name() func_name. don't want call function when bind handler - want reference it.
  2. calling bind won't good, because #runtime doesn't exist until after you've clicked .rem. that's why need either live or on (depending upon jquery version).

and measure: here's reference on why should using jquery.on anyway.


Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -