jQuery – :checkbox Selector

The jQuery checkbox selector selects all elements of type checkbox. jQuery(‘:checkbox’) is equivalent to jQuery(‘[type=checkbox]‘) or jQuery(‘input:checkbox’)

Source Code

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

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

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

Demo

Following example finds all checkbox inputs in a div (having id=”div1″) and create a border around them.

checkbox 1
checkbox 2
checkbox 3
checkbox 4

,

No comments yet.

Leave a Reply