jQuery Selector :checked

Introduction

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

Syntax

$(":checked")

Select all checked elements (checkboxes or radio buttons):

jQuery .wrap method can highlight the selected elements.

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(){
  $(":checked").wrap("<span style='background-color:red'>");
});/*from   w ww .  j a  v a  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>
  airplane: <input type="checkbox" name="vehicle" value="Airplane"><br>
  <input type="submit">
<form>
</body>
</html>



PreviousNext

Related