Skip to content

Instantly share code, notes, and snippets.

@mazfreelance
Last active August 24, 2017 03:27
Show Gist options
  • Save mazfreelance/27c014a5760b734b9f075b7ea86802ce to your computer and use it in GitHub Desktop.
Save mazfreelance/27c014a5760b734b9f075b7ea86802ce to your computer and use it in GitHub Desktop.
JQUERY: Check & Uncheck using selection
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<SCRIPT language="javascript">
$(document).ready(function() {
$("#check").change(function() {
var d = $(this).val();
if(d == 'parent'){
$(".child").prop("checked", !d.checked);
}
});
$("#check").change(function() {
var d = $(this).val();
if(d == 'parentnone'){
$(".child").prop("checked", false);
}
});
});
</SCRIPT>
<select id="check">
<option>Select</option>
<option value="parent" data-checked='false'>All</option>
<option value="parentnone" data-checked='false'> None </option>
</select>
<hr/>
<ul>
<li>
<input type="checkbox" class="child" /> Checkbox 1</li>
<li>
<input type="checkbox" class="child" /> Checkbox 2</li>
<li>
<input type="checkbox" class="child" /> Checkbox 3</li>
</ul>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment