jQuery Selector :checkbox

Introduction

The :checkbox selector selects input elements with type=checkbox.

$(":checkbox")

Select all <input> elements with type="checkbox":

View in separate window

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
  $(":checkbox").wrap("<span style='background-color:red'>");
});// w  w w.ja va2 s  . c om
</script>
</head>
<body>

<form action="">
  Name: <input type="text" name="user"><br>
  I have a bike: <input type="checkbox" name="vehicle" value="Bike"><br>
  I have a car: <input type="checkbox" name="vehicle" value="Car"><br>
  I have an airplane: <input type="checkbox" name="vehicle" value="Airplane"><br>
  <input type="submit">
</form>
</body>
</html>



PreviousNext

Related