Thursday, May 17, 2012

jQuery .click() - click event handler

In the following example, if clicked on <p id="clickme">, the click event handlers of both <p id="clickme"> and document will be triggered; if click on any space outside <p id="clickme">, only the event handler of document will be triggered.

<!doctype html>
<head>
 <title>Mobile-Web-App: jQuery .click()</title>
 <meta charset="utf-8">
 <script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
 <script>
  $(document).ready(function(){
   $("#clickme").click(function(){
    alert("'clickme' Clicked!");
   });
   
   $(document).click(function(){
    alert("document Clicked!");
   });
  });
 </script>
 
</head>
<body>
<p><b>Mobile-Web-App: jQuery .click()</b></P>
<p id="clickme">Click Me</p>

</body>
</html>


jQuery .click()


Related:
- Handle event using .bind() in jQuery
- Handle event using .bind() and .unbind() in jQuery
- Handle event using .live() in jQuery


No comments:

Post a Comment