Skip to content

Instantly share code, notes, and snippets.

@ybouhjira
Created January 15, 2017 18:39
Show Gist options
  • Save ybouhjira/b918f083719111062a4d9e5aae0963e0 to your computer and use it in GitHub Desktop.
Save ybouhjira/b918f083719111062a4d9e5aae0963e0 to your computer and use it in GitHub Desktop.
Awesome attribute
<!DOCTYPE html>
<html>
<head>
<title>
</title>
</head>
<body>
<radiogroup data-show-when-checked="mydiv" data-enable-on="oui">
<input type="radio" name="myradio" value="oui" >
<input type="radio" name="myradio" value="non">
</radiogroup>
<div id="mydiv">
Hello
</div>
<script type="text/javascript">
$(function() {
var showAttr = 'data-show-when-checked';
$('[' + showAttr + ']').change(function() {
var slef = $(this);
if (self.find('input:checked').val() === self.attr('data-enable-on')) {
$('#' + self.attr(showAttr)).show();
}
})
})
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment