Handle click event once

Description

The following code shows how to handle click event once.

Example


<html>
<head>
<style type="text/css">
.div1 {<!--   w ww  .j  a  v  a 2 s . c o  m-->
  width: 100;
  height: 100;
  background-color: blue;
}

.div2 {
  width: 100;
  height: 100;
  background-color: red;
}
</style>
<script
  src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
  $(function() {

    $(".div1").one("click", function() {
      $("body").append("<p>clicked div 1 </p>");
    });
    $(".div2").bind("click", function() {
      $("body").append("<p>clicked div 2 </p>");
    });
  });
</script>
</head>
<body>
  <div class="div1">j ava2s.com</div>
  <div class="div2">jav a2s.com</div>
</body>
</html>

Click to view the demo





















Home »
  jQuery »
    jQuery Example »




Animation
DOM
Event
Form
List
Select
Style
Table
Utilities