Edit
Below is a demo without javascript:
CSS
.big input[name=chb]{ display:none; } .big label{ display:inline-block; background-color:red; width:120px; height:120px; padding:5px 10px; } .big input[type="radio"]:checked + label { background-color:blue; }
HTML (note: label should appear after input )
<div class="big"> <input id="chb_1" name="chb" type="radio" /> <label for="chb_1">This is a div 1 </label> </div> <br /> <div class="big"> <input id="chb_2" name="chb" type="radio" /> <label for="chb_2">This is a div 2 </label> </div>
Using jQuery:
Instead of having multiple ID entries (which is WRONG), use the name attribute!
By correctly assigning your radio buttons, you join them in a happy family of radio stations.
jsFiddle demo HTML:
<div class="big"> This is a div 1 <input name="chb" type="radio" /> </div> <div class="big"> This is a div 2 <input name="chb" type="radio" /> </div>
JQuery
$('.big').click(function() { $('input[name="chb"]', this).prop("checked",true); $('.big').removeClass('hli'); $(this).addClass('hli'); });
From DOCS: http://api.jquery.com/prop/
Roko C. Buljan
source share