Skip to content

Instantly share code, notes, and snippets.

Last active January 3, 2016 17:09
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save nextechu/8494411 to your computer and use it in GitHub Desktop.
A click event handler has been assigned to the HTML input button. When the button is clicked, jQuery finds all the checkboxes with name “chk” using input:checkbox[name=chk] selector and then the Id, value and state of the all HTML input checkboxes are displayed in alert using jQuery.
<!DOCTYPE html>
<html lang="en">
<meta charset="utf-8">
<title>Select checkboxes</title>
<input type="checkbox" id="Checkbox1" name ="chk" value ="1" />
<input type="checkbox" id="Checkbox2" name ="chk" value ="2" />
<input type="checkbox" id="Checkbox3" name ="chk" value ="3" />
<input type="checkbox" id="Checkbox4" name ="chk" value ="4" />
<input type="button" id="demo" value ="Demo" />
<script src=""></script>
$("#demo").live("click", function () {
$("input:checkbox[name=chk]").each(function () {
alert("Id: " + $(this).attr("id") + " Value: " + $(this).val() + " Checked: " + $(this).is(":checked"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment