Skip to main content

JQuery Custom Image Checkbox code not toggling



I am using the following code to make a custom checkbox with my own images.





First I included JQuery and added the JQuery code for the required functionality:







<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>

<script>

$(document).ready(function(){



$("#moreinfo").change(function() {

if(this.checked) {

$(this).prev().attr("src", "checkbox_unchecked.gif");

} else {

$(this).prev().attr("src", "checkbox_checked.gif");

}

});



});



</script>





Next...here's the HTML:







<label for="moreinfo">

<img src="checkbox_unchecked.gif"/>

<input name="moreinfo" type="checkbox" id="moreinfo" style="display:none">

</label>







The unchecked image is there but when I click on it, it doesn't change/toggle.





I'm I missing something?





UPDATE:





Testing this full code locally and it's not working...







<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>

<head>

<title>



<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>

<script>

$(document).ready(function(){



$("#moreinfo").change(function() {

if(this.checked) {

$(this).prev().attr("src", "http://icdn.pro/images/en/v/e/verify-correct-icone-9268-48.png");

} else {

$(this).prev().attr("src", "http://www.theology.edu/Remata/Android/Help/wrongx_icon.png");

}

});





});



</script>



</title>









</head>

<body>







<label for="moreinfo">

<img src="http://www.theology.edu/Remata/Android/Help/wrongx_icon.png"/>

<input name="moreinfo" type="checkbox" id="moreinfo" style="display:none">

</label>









</body>

</html>




Comments

Popular posts from this blog

Slow Android emulator

I have a 2.67 GHz Celeron processor, 1.21 GB of RAM on a x86 Windows XP Professional machine. My understanding is that the Android emulator should start fairly quickly on such a machine, but for me it does not. I have followed all instructions in setting up the IDE, SDKs, JDKs and such and have had some success in staring the emulator quickly but is very particulary. How can I, if possible, fix this problem?