:checked Selector - Javascript jQuery Selector

Javascript examples for jQuery Selector:checked

Description

The :checked selector selects all checked checkboxes or radio buttons.

The following code shows how to select all checked elements (checkboxes or radio buttons):

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $(":checked").wrap("<span style='background-color:red'>");
});//from  ww w .  j  a va 2 s .  co m
</script>
</head>
<body>

<form action="">
  Name: <input type="text" name="user"><br>
  bike: <input type="checkbox" name="vehicle" value="Bike"><br>
  car: <input type="checkbox" name="vehicle" value="Car" checked="checked"><br>
  <input type="submit">
</form>

</body>
</html>

Related Tutorials