by @kodeazy
JQuery How to get all selected checkboxes with in certain ID in HTML
- I have a group of check boxes inside an ID in HTML.
-
To get all selected checkboxes after clicking the
button
below is the syntax.$("#checkboxData input[type=checkbox]").each(function() { if($(this).is(':checked')){ //implementation code } })
- Below is the sample example of displaying all the selected checkboxes after clicking a button in HTML.
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
</head>
<form id="checkboxData">
<input type="checkbox" name="Audi" value="Audi">Audi
<br>
<input type="checkbox" name="BMW" value="BMW">BMW
<br>
<input type="checkbox" name="Ford" value="Ford">Ford
<br>
<input type="checkbox" name="Ferrari" value="Ferrari">Ferrari
<br>
<button type="button" onclick="selectedTags()">submit</button>
</form>
<div id="checkedItems"></div>
<script>
function selectedTags(){
$("#checkedItems").empty();
$("#checkboxData input[type=checkbox]").each(function() {
if($(this).is(':checked')){
$("#checkedItems").append(this.value+"</br>");
}
})
}
</script>
</html>