Jquery Checkbox with Images - Question
Hi all
I have 3 checkboxes on my form each with a unique ID. When I click one, I change the image accordingly (using image replacement).
I use the following code to mamage the click event of each checkbox:
- $("#support").live('click',function() {
if(this.checked) {
$(this).prev().attr("src", "/images/icons/tick-on.jpg");
} else {
$(this).prev().attr("src", "/images/icons/tick-off.jpg");
}
});
- $("#services").live('click',function() {
if(this.checked) {
$(this).prev().attr("src", "/images/icons/tick-on.jpg");
} else {
$(this).prev().attr("src", "/images/icons/tick-off.jpg");
}
});
- $("#help").live('click',function() {
if(this.checked) {
$(this).prev().attr("src", "/images/icons/tick-on.jpg");
} else {
$(this).prev().attr("src", "/images/icons/tick-off.jpg");
}
});
now there is every possibility that I need to extend the form to include many more checkboxes so is there a way of looping the code above to work with any amount of checkboxes and not having to specify the ID of the checkbox it relates to?
Thanks for reading.