本文實例講述了jQuery實現查找最近父節點的方法。分享給大家供大家參考,具體如下:
這裡演示查找當前控件最近的table
<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>