Thanks Kip, for those who may be looking to achieve the same using $(this) whilst iterating or associating within a function:
$("label[for="+$(this).attr("id")+"]").addClass( "orienSel" );
I looked for a while whilst working this project but couldn't find a good example so I hope this helps others who may be looking to resolve the same issue.
In the example above, my objective was to hide the radio inputs and style the labels to provide a slicker user experience (changing the orientation of the flowchart).
You can see an example here
If you like the example, here is the css:
.orientation { position: absolute; top: -9999px; left: -9999px;}
.orienlabel{background:#1a97d4 url('http://www.ifreight.solutions/process.html/images/icons/flowChart.png') no-repeat 2px 5px; background-size: 40px auto;color:#fff; width:50px;height:50px;display:inline-block; border-radius:50%;color:transparent;cursor:pointer;}
.orR{ background-position: 9px -57px;}
.orT{ background-position: 2px -120px;}
.orB{ background-position: 6px -177px;}
.orienSel {background-color:#323232;}
and the relevant part of the JavaScript:
function changeHandler() {
$(".orienSel").removeClass( "orienSel" );
if(this.checked) {
$("label[for="+$(this).attr("id")+"]").addClass( "orienSel" );
}
};
An alternate root to the original question, given the label follows the input, you could go with a pure css solution and avoid using JavaScript altogether...:
input[type=checkbox]:checked+label {}