I'm trying 开发者_开发知识库to select
<input type="button" class="set_image_btn" value="Set image" />
with
$('.set_image_btn').live("click", function(){
alert('CLICKED!');
});
but for some reason it won't work. The HTML is made by JavaScript in my HTML file and I suspect my .js file is unable to get this, but I'm not sure how to properly select it.
Make sure you are calling the code after you created the html with javascript, so you'd have something like this:
$('<input type="button" ...').appendTo("body"); //I asume you create with it.
alert($('.set_image_btn').size()); //This is a test alert. Should alert '1'
$('.set_image_btn').live("click", function(){ alert('CLICKED!'); });
If the test alert alerts '0' it means you didn't create the element or you didn't append it to the page.
Hope this helps. Cheers
精彩评论