开发者

Can't select button with jQuery

开发者 https://www.devze.com 2023-03-17 08:22 出处:网络
I\'m trying 开发者_开发知识库to select <input type=\"button\" class=\"set_image_btn\" value=\"Set image\" />

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

0

精彩评论

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