How to get checkbox checked attribute id when button clicked in jQuery.
I have list of check boxes with attribute id and a button when I check on checkbox and click on button it will return id of selected checkbox.
index.html:
Here, we created one HTML file. Which is hold HTML and Jquiry code.
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"> </script> </head> <body> <div id="checkboxlist"> <div><input type="checkbox" id="Java" class="chk">Java</div> <div><input type="checkbox" id="Php" class="chk">Php</div> <div><input type="checkbox" id="Html" class="chk">Html</div> <div><input type="checkbox" id="Python" class="chk">Python</div> <div> <input type="button" value="Click" id="buttonClass"> </div> </div> </div> <script> $("#buttonClass").on("click", function() { var checkedIds = $(".chk:checked").map(function() { return this.id; }).toArray(); alert(checkedIds.join(", ")); }); </script> </body> </html>