Changing image src with jQuery in CodeIgniter platform
I'm having a bit of trouble changing the image source, using jQuery, in my CodeIgniter website.
I'm building a custom onclick() function attached to my images (i have a list of 'checkbox' images inside a list, and when clicked I want to replace it with the 'checked' image), but when I try to alert out the src of that开发者_开发百科 image all I get is 'undefined'. Any help would be appreciated.
HTML code:
<img src="<?php echo imagePath(); ?>icons/checkbox_empty.png" class="checkbox1" onclick="checkbox(1)" /> html text here...
<img src="<?php echo imagePath(); ?>icons/checkbox_empty.png" class="checkbox2" onclick="checkbox(2)" /> html text here...
and so on...
jQuery code:
function checkbox(number){
var image = $('#checkbox'+number).attr("src");
alert(image);
}
Once again, any help really would be appreciated. Tim.
You should use the class selector, not the id selector:
.checkbox1
not #checkbox1
Give that a shot.
精彩评论