jQuery On click Event function


jquery jQuery On click Event function Jquery Start

How to call the function on click using jQuery?

We can call JavaScript or jQuery code when we click on any HTML tag. Without using the onclick attribute of HTML tag we can call the JavaScript or jQuery code.

Syntax of jQuery click method

<script type="text/javascript"> $("HTMLtagName OR .className or #Id").click(function() { statements; }); </script>

Example of on jQuery Click method

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <button> Click Me For Calling jQuery Click Method ! </button> <script type="text/javascript"> $("button").click(function() { alert('You have clicked the Button'); }); </script>

Output:

In above code we have called the an alert() function on button click. We can choose Class and unique specifier ID also.

Button with class .mybtn

<script type="text/javascript"> $("button .mybtn").click(function() { alert('You have clicked the Button with calss .mybtn '); }); </script>
jquery Jquery Start Chapter Next »