checked selector in jQuery with example

checked selector returns all the checked input elements from the group of elements.

Example 1 :

    <title>checked Selector</title>
    <script type="text/javascript" src=""> </script>
    <script type="text/javascript">
        $(document).ready(function () {
            $("#myButton").click(function () {
                var text = "";
                $(":Checked").each(function () {
                    text = text + "   " + $(this).val();
                var spanText = $("#checkedSpan").html();
                if (spanText != null) {
                    $("#checkedSpan").innerHTML = " ";
                $("#checkedSpan").html("You selected: " + text);
    <input type="checkbox" name="BE" value="BE">BE
    <input type="checkbox" name="ME" value="ME">ME
    <input type="checkbox" name="MS" value="MS">MS
    <input type="checkbox" name="MCA" value="MCA">MCA
    <button id="myButton">Click</button>
    <button onclick="location.reload();">Reset</button><br>
    <span id="checkedSpan"></span>

Demo :

In the above example, we have used checked selector. Checked selector selects all the checked elements from the group of elements. In above example, on button click the selector selects the checked checkboxes and display them.


Post a Comment