How to do Check box check event dynamically?


Some times we may have some values are attaching to the checkbox ids, like example below. Using $("[Id*='isAccommadation']") code we can get selected checkbox value and we can do the event operations.

This is not limited to check box. This will applicable for all HTML elements.


<!DOCTYPE html>

<html>

<head>

    <title></title>

<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>

    <script language="javascript">

        $(document).ready(function() {



            $("[Id*='isAccommadation']").bind("click", function () {

                alert(this.value);

            });



        });

    </script>

</head>

    <body>

        <div id="hai">



        <input type='checkbox' name="1" id='isAccommadation_1' value="JQuery" />JQuery<br/>

        <input type='checkbox' name="2" id='isAccommadation_2' value="Example" />Example<br/>

        <input  type='checkbox' name="3" id='isAccommadation_3' value="Code" />Code<br/>

            </div>

    </body>

</html>


Post a Comment