jQuery prop() get and set checked attribute

Description

jQuery prop() get and set checked attribute

View in separate window

<!DOCTYPE html>
<html>
<head>
<script 
 src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js">
</script>/*from   w  ww  .  j  a v  a 2s.c  o m*/
<script>
$(document).ready(function(){
  $("button").click(function(){
    $("#p1").html("attr('checked'): " + 
                  $("input").attr('checked') + 
                  "<br>prop('checked'): " + 
                  $("input").prop('checked'));
  });
});
</script>
</head>
<body>

<button>Check value of attr() and prop()</button>
<br><br>

<input id="check1" type="checkbox" checked="checked">
<label for="check1">Check me</label>
<p id="p1"></p>

</body>
</html>



PreviousNext

Related