Single JQuery for Multiple Checkbox Click Event

Once I was in situation when I have to call same function for all checkbox. I was wondering how to do it without writing code for every checkbox. Then I come across with a solution of using JQuery. I used JQuery to find click event of all checkbox on a form element. Below is the code snippet:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js" type="text/javascript"></script>

<script language="javascript">

    $(document).ready(function () {

        $("form :checkbox").click(function () {

            alert('hi : ' + this.name);

        });

    });

Really JQuery is more powerful than JavaScript. I have done it for checkbox, likewise we can find the events of other controls also. Enjoy have fun with JQuery.
 

X

Build smarter apps with Machine Learning, Bots, Cognitive Services - Start free.

Start Learning Now