Get closest element

Description

The following code shows how to get closest element.

Example


<html>
<head>
<script
  src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript">
  $(document).ready(function() {<!--from   ww  w. j  a v a  2 s .co m-->
    $(document).bind("click", function(e) {
      $(e.target).closest("span").text("java2s.com");
    });
  });
</script>
</head>
<body>
<body>
  <div>
    <span>span</span><span>span</span><span>span</span>
  </div>
</body>
</html>

Click to view the demo





















Home »
  jQuery »
    jQuery Example »




Animation
DOM
Event
Form
List
Select
Style
Table
Utilities