jQuery – :checked Selector

The jQuery checked selector matches all elements that are checked. The :checked selector works for checkboxes and radio buttons. For select elements, use the :selected selector.

Source Code

<!DOCTYPE html>
<html>
<head>
  <script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>

<div id="div1">
	<input type="checkbox" checked="checked"/> checkbox 1
	<input type="checkbox" /> checkbox 2
</div>
<div  id="div2">
	<input type="checkbox" /> checkbox 3
	<input type="checkbox" checked="checked"/> checkbox 4
</div>
<button>Click Here</button>

  
<script>
jQuery("button").click(function () {
	jQuery("input:checked").wrap('<span></span>').parent().css({border:"3px #1E8CBE solid"});
});
</script>
</body>
</html>

Demo

Following example finds all input elements that are checked and create a border around them.

checkbox 1
checkbox 2
checkbox 3
checkbox 4

,

No comments yet.

Leave a Reply