How can I move each label in front of the input element they\'re next to using jQuery?
$('.select .classCheckBox label').each(function() {
$(this).insertBefore( $(this).prev('input') );
});
DEMO
$('.select .classCheckBox label') select each label within each .classCheckBox
$(this) within loop point to label
.insertBefore() insert any element before the matched element that passed as argument
$(this).prev('input') points the input before label
so, $(this).insertBefore( $(this).prev('input') ) will insert each label before its previous input
Related refs:
.insertBefore()
.prev()
.each()
$('.select .classCheckBox input').each(function() {
$(this).insertAfter( $(this).next('label') );
});
DEMO
OR
$('.select .classCheckBox input').each(function() {
$(this).before( $(this).next('label') );
});
DEMO