Jquery method to obtain the parent node: It can be obtained through the parent method, such as [$(selector).parent(filter)]. The parent method can return the direct parent element of the selected element.
The operating environment of this tutorial: Windows 10 system, jquery version 2.2.4. This method is suitable for all brands of computers.
(Learning video sharing: jquery video tutorial)
Method introduction:
parent() method returns the direct parent element of the selected element.
Syntax:
$(selector).parent(filter)
Parameters:
$(document).ready(function(){ $("span").parent().css({"color":"red","border":"2px solid red"}); });
body (great-great-grandparent)div (great-grandparent) ul (grandparent)li (direct parent) span
The above is the detailed content of How to get the parent node in jquery. For more information, please follow other related articles on the PHP Chinese website!