Below you will see the code I am working on and an included JSFiddle.
Issue:
- The focus is running before the click/change so the margin is moving before the radio button can be selected.
Please explain the code so I can learn from this. If you do not have a solution any hints or direction would also be helpful. Thanks in advance!
http://jsfiddle.net/nLgqhqwc/6/
HTML
<div class="panel">
<input type="text"/>
</div>
<div class="panel">
<input type="text"/>
</div>
<div class="panel">
<select>
<option>option</option>
</select>
</div>
<div class="panel">
<input type="radio"/>
</div>
<div class="panel">
<input type="checkbox"/>
</div>
CSS
.panel{
padding:15px;
background:grey;
margin-bottom:15px;
}
.panel-primary{
margin:0 15px 0 15px;
background:blue;
margin-bottom:15px;
}
jQuery
$(document).ready(function () {
$('.panel').click(function () {
event.stopPropagation();
$('.panel').removeClass('panel-primary');
$(this).addClass('panel-primary');
});
$('input, select').bind('focus blur', function (event) {
event.stopPropagation();
$('.panel').removeClass('panel-primary');
$(this).closest(".panel").addClass('panel-primary');
});
$('input[type=radio]').change(function () {
event.stopPropagation();
$('.panel').removeClass('panel-primary mrgn-lft-lg');
$(this).closest(".panel").addClass('panel-primary');
});
});