How do I change the background colour of a <label> if a checkbox is checked, using JQuery?
<p>Using JQuery, is there a more efficient way of writing this code? See below</p>

<p>The JQuery:</p>

<pre><code>$("#ex1").live("click", function(){
if($("#ex1").attr("checked")==true){ 
    $(this).parent().removeClass("im-unchecked").addClass("im-checked"); 
}
else if($("#ex1").attr("checked")==false){ 
    $(this).parent().removeClass("im-checked").addClass("im-unchecked");
}});


$("#ex2").live("click", function(){
if($("#ex2").attr("checked")==true){ 
    $(this).parent().removeClass("im-unchecked").addClass("im-checked"); 
}
else if($("#ex2").attr("checked")==false){ 
    $(this).parent().removeClass("im-checked").addClass("im-unchecked"); 
}});
</code></pre>

<p>The HTML I'm working with:</p>

<pre><code>&lt;label for="ex1" id="ex-label-1"&gt;Y &lt;input type="checkbox" id="ex1" name="ex" value="Y" &lt;% If IsEx("Y") then%&gt;checked&lt;%end if%&gt; /&gt;&lt;/label&gt;
&lt;label for="ex2" id="ex-label-2"&gt;M &lt;input type="checkbox" id="ex2" name="ex" value="M" &lt;% If IsEx("M") then%&gt;checked&lt;%end if%&gt; /&gt;&lt;/label&gt;
&lt;label for="ex5" id="ex-label-3"&gt;X &lt;input type="checkbox" id="ex5" name="ex" value="X" &lt;% If IsEx("X") then %&gt;checked&lt;%end if%&gt; /&gt;&lt;/label&gt;
&lt;label for="ex3" id="ex-label-4"&gt;N &lt;input type="checkbox" id="ex3" name="ex" value="N" &lt;% If IsEx("N") then %&gt;checked&lt;%end if%&gt; /&gt;&lt;/label&gt;
&lt;label for="ex6" id="ex-label-5"&gt;L &lt;input type="checkbox" id="ex6" name="ex" value="L" &lt;% If IsEx("L") then %&gt;checked&lt;%end if%&gt; /&gt;&lt;/label&gt;
&lt;label for="ex7" id="ex-label-6"&gt;Z &lt;input type="checkbox" id="ex7" name="ex" value="Z" &lt;% If IsEx("Z") then %&gt;checked&lt;%end if%&gt; /&gt;&lt;/label&gt;
&lt;label for="ex4" id="ex-label-7"&gt;A &lt;input type="checkbox" id="ex4" name="ex" value="A" &lt;% If IsEx("A") then %&gt;checked&lt;%end if%&gt; /&gt;&lt;/label&gt;    
</code></pre>

<p>Sorry guys I'm a novice as JavaScript/JQuery</p>

<p>Any help would be greatly appreciated, Thanks</p>
