0

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.

Tim Blackburn
  • 1,086
  • 2
  • 11
  • 13

1 Answers1

0

You should use the class selector, not the id selector: .checkbox1 not #checkbox1

Give that a shot.

Tim Withers
  • 12,072
  • 5
  • 43
  • 67
  • OMG... thanks a million Tim... I feel like such an idiot, how I missed that I don't know!!! lol. Sorry that I cannot 'upvote' your reply, I'm a new member and it wont let me... also, am I meant to mark this as 'answered' somehow? – Tim Blackburn Oct 09 '11 at 16:51