Home > Article > Web Front-end > jquery traverses parent() method
[Introduction] jquery a traverses nodes-parent() method The parent([selector]) method returns a collection of parent elements of each matching element. Here selector is an optional parameter and is a selector expression used to filter parent elements. HTML code:
jquery tutorial
jquery plugin
jquery code:
view sourceprint?1 $("p").parent().css tutorial("background", "green");//In this way, the background color of the parent element p of the three p's will turn green
Then pass in a parameter ".selected" to parent
jquery code:
view sourceprint?1 $("p").parent(".selected").css("background", " green");//In this way, the background color of the parent element p class of the three p's is "selected" will turn green
The above is the detailed content of jquery traverses parent() method. For more information, please follow other related articles on the PHP Chinese website!