How to get value from the first checkbox which is not hidden in jQuery?

jQueryWeb DevelopmentObject Oriented Programming

To get value from the first checkbox, which is not hidden, use the :visible selector. Following is the code −


 Live Demo

<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initialscale=1.0">
<link rel="stylesheet"
   .notShown {
      display: none;
<script src=""></script>
<script src=""></script>
<div class='form'>
<input class="demo notShown" type="checkbox" value="first"
checked="checked" />
<br />
<input class="demo" type="checkbox" value="second"
<br />
<input class="demo" type="checkbox" value="third" />
<br />
<input class="demo " type="checkbox" value="fourth"
checked="checked" />
   var v=$('input:checkbox:checked:visible:first').val();

To run the above program, save the file name “anyName.html(index.html)” and right click on the file. Select the option “Open with Live Server” in VS Code editor.

This will produce the following output displaying the visible value “second” in console −

Updated on 01-Sep-2020 11:55:11