Skip to content

Instantly share code, notes, and snippets.

@Macagare
Created November 2, 2012 08:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Macagare/3999399 to your computer and use it in GitHub Desktop.
Save Macagare/3999399 to your computer and use it in GitHub Desktop.
Javascript: Hiding radio buttons and styling labels with jQuery
<html>
<head>
<script type="text/javascript">
$(document).ready(function () {
$('input').click(function () {
$('input:not(:checked)').parent('label').removeClass("style1");
$('input:checked').parent('label').addClass("style1");
});
});​
</script>
<style>
input {display: none}
.style1 {background: red;}​
</style>
</head>
<body>
<label><input type="radio" name="newsletter" />Hourly</label>
<label><input type="radio" name="newsletter" />Daily</label>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment