开发者

jQuery,Input buttons work in markup, but not when prepended?

开发者 https://www.devze.com 2022-12-24 11:17 出处:网络
I have to buttons, image input that work fine when in 开发者_如何学Gothe markup like this, <input type=\"image\" class=\"play\" src=\"images/play.png\" />

I have to buttons, image input that work fine when in 开发者_如何学Gothe markup like this,

<input type="image" class="play" src="images/play.png" />
<input type="image" class="pause" src="images/pause.png" />

But as soon as I try to prepend() it to a generated they still appear, but the click function does not work anymore.

$('.gallery-nav').prepend('<input type="image" class="play" src="images/play.png" /><input type="image" class="pause" src="images/pause.png" />');

Any idea why? Thank you.


Try using live instead of click.

live: attach a handler to the event for all elements which match the current selector, now or in the future.

$("input.play").live("click", function(){
    // write your code here
});


Try using the live() method for that:

// for play button
$('.play').live('click', function(){
  // your code
});

// for pause button
$('.pause').live('click', function(){
  // your code
});


$('.mydivClass').prepend('<a href="#" id="btnLINK">OK</a>');

$('#btnLINK').live("click",function() { 
    alert ("EUREKA")
    return false;
});
0

精彩评论

暂无评论...
验证码 换一张
取 消