Created
July 19, 2013 09:37
-
-
Save willhalling/6037962 to your computer and use it in GitHub Desktop.
Simple jQuery function to change class of labels when radio buttons are selected.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script> | |
<title>Select/Change option</title> | |
<style type="text/css"> | |
.red {color: red;} | |
.black {color: black;} | |
</style> | |
<script type="text/javascript"> | |
$(function() { | |
// When the value of the radio change | |
$('.radioPanel [type="radio"]').on('change', function() { | |
$(this) | |
.prev().addClass('red') | |
.siblings().removeClass('red'); | |
}); | |
}); | |
</script> | |
</head> | |
<body> | |
<div class="radioPanel"> | |
<label for="Milk">Milk</label> | |
<input type="radio" id="Milk" name="group1" value="Milk"> | |
<label for="Butter">Butter</label> | |
<input type="radio" name="group1" value="Butter" checked> | |
<label for="Cheese">Cheese</label> | |
<input type="radio" id="Cheese" name="group1" value="Cheese"> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment