Languages
[Edit]
EN

jQuery - mouse click event

9 points
Created by:
AnnLen
9150

Using jQuery it is possible to create click event in following ways. This function works similar to onclick event.

1. click method example

// ONLINE-RUNNER:browser;

<!doctype html>
<html>
<head>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.0.0/jquery.min.js"></script>
</head>
<body>
  <button id="button">Click me!</button>
  <script>

    $(document).ready(function() {
		var button = $('#button');
      
      	button.click(function() {
        	button.text('Button clicked!');
        });
    });

  </script>
</body>
</html>

2. on method with event name example

// ONLINE-RUNNER:browser;

<!doctype html>
<html>
<head>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.0.0/jquery.min.js"></script>
</head>
<body>
  <button id="button">Click me!</button>
  <script>

    $(document).ready(function() {
		var button = $('#button');
      
      	button.on('click', function() {
        	button.text('Button clicked!');
        });
    });

  </script>
</body>
</html>

3. on method with event object example

// ONLINE-RUNNER:browser;

<!doctype html>
<html>
<head>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.0.0/jquery.min.js"></script>
</head>
<body>
  <button id="button">Click me!</button>
  <script>

    $(document).ready(function() {
		var button = $('#button');
      
      	button.on({
            'click': function() {
        	    button.text('Button clicked!');
            }
        });
    });

  </script>
</body>
</html>
Native Advertising
50 000 ad impressions - 449$
🚀
Get your tech brand or product in front of software developers.
For more information contact us:
Red dot
Dirask - friendly IT community for everyone.

❤️💻 🙂

Join