Home  >  Article  >  Web Front-end  >  jQuery implements the method of finding the nearest parent node

jQuery implements the method of finding the nearest parent node

韦小宝
韦小宝Original
2017-11-29 10:18:112770browse

The example of this article describes the method of jQuery to find the nearest parent node. For students who are not familiar with jQuery, let’s learn jQuery together!

Here is a demonstration of finding the nearest table code of 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>

The above is how jQuery implements finding the nearest parent node. For more jQuery-related content, please visit this site Search~

Related recommendations:

##JQuery node element attribute operation method_jquery

Detailed examples of selector and DOM node operations in JQuery

Analysis of examples of DOM operations in jQuery

The above is the detailed content of jQuery implements the method of finding the nearest parent node. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn