Thank you to @Joseinnewworld who just bought 4 of our #NFTs, your appreciation means a lot to us as builders. We also will process 1 NFT gift as our gratitude to you who contribute as a Quality Control of our site 🤩 #eCash $XEC #nftcollector #NFTDrop #BlockchainSimplicity #NFT pic.twitter.com/01ezqkSdmb
— Gaexe (@gaexe_) January 18, 2025
Description: matches all checked or selected elements.
The :checked selector works on the checkboxes, radio buttons, and options of the selected element.
To retrieve data or values from selected elements, simply use the :selected selector.
Example 1
Set how many input elements need to be selected.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>checked demo</title>
<style>
div {
color: red;
}
</style>
<script src="https://code.jquery.com/jquery-3.4.1.js"></script>
</head>
<body>
<form>
<p>
<input type="checkbox" name="newsletter" value="Hourly" checked="checked">
<input type="checkbox" name="newsletter" value="Daily">
<input type="checkbox" name="newsletter" value="Weekly">
<input type="checkbox" name="newsletter" value="Monthly" checked>
<input type="checkbox" name="newsletter" value="Yearly">
</p>
</form>
<div></div>
<script>
var countChecked = function() {
var n = $( "input:checked" ).length;
$( "div" ).text( n + (n === 1 ? " is" : " are") + " checked!" );
};
countChecked();
$( "input[type=checkbox]" ).on( "click", countChecked );
</script>
</body>
</html>
Demo 1
https://jsfiddle.net/gatewan/rd6hnvLy/3/
Example 2
Identifies the selected radio button.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>checked demo</title>
<style>
input, label {
line-height: 1.5em;
}
</style>
<script src="https://code.jquery.com/jquery-3.4.1.js"></script>
</head>
<body>
<form>
<div>
<input type="radio" name="fruit" value="orange" id="orange">
<label for="orange">orange</label>
</div>
<div>
<input type="radio" name="fruit" value="apple" id="apple">
<label for="apple">apple</label>
</div>
<div>
<input type="radio" name="fruit" value="banana" id="banana">
<label for="banana">banana</label>
</div>
<div id="log"></div>
</form>
<script>
$( "input" ).on( "click", function() {
$( "#log" ).html( $( "input:checked" ).val() + " is checked!" );
});
</script>
</body>
</html>