jQuery implements a method of finding the nearest parent node

  • 2021-06-29 10:01:31
  • OfStack

This article provides an example of how jQuery implements finding the nearest parent node.Share it for your reference, as follows:

This demonstrates finding the nearest table for the current control


<html>
  <head>
    <title>usually function</title>
  </head>
  <body>
    <table name="name_table1">
      <tr>
        <td>table1</td>
      </tr>
    </table>
    <table name="name_table2">
      <tr>
        <td>table2</td>
      </tr>
    </table>
    <table name="name_table3">
      <tr>
        <td>table3</td>
      </tr>
    </table>
  </body>
<html>
<script type="text/javascript" src="jquery-1.4.4.js"></script>
<script>
$(function(){
  $("td").bind("click",function(){
    //alert($(this).html());
    alert($(this).closest("table").attr("name"));
  });
});
</script>

More readers interested in jQuery-related content can view this site's topics: jQuery Operation DOM Node Method Summary, jQuery Extended Skills Summary, jQuery Common Plug-ins and Usages Summary, jQuery Dragging Special Effects and Skills Summary, jQuery Table (table) Operation Skills Summary, Ajax Usage Summary in jquery, andSummary of jQuery Common Classic Effects, Summary of jQuery Animation and Utility, and Summary of jquery Selector Usage

I hope that the description in this paper will be helpful to everyone's jQuery program design.


Related articles: