Home > Web Front-end > JS Tutorial > body text

jQuery implements the method of finding the nearest parent node

韦小宝
Release: 2017-11-29 10:18:11
Original
2769 people have browsed it

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>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!