The content of this article is about how to connect addback() and end() (code) in jquery. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>串联addback()和end()</title> <script type="text/javascript" src="../js/jquery-3.3.1.min.js"></script> <script type="text/javascript"> $(function(){ // $("div").find("p").css("border","1px solid red"); //div下查找p,addBack()回溯找到div,.css()对两者同时添加样式 // $("div").find("p").addBack().css("border","1px solid red"); // 注意:对于筛选或查找后的元素,要加入先前所选元素时,使用addBack()方法会很有效,符合链式设计原则 //返回jQuery对象,为p元素添加边框,同时为div添加背景 $("div").find("p").css("border","1px solid red").end().css("background","#ff0"); }); </script></head><body> <div> <p>天将降大任于斯人也</p> <p>必先劳其筋骨,苦其心志,空乏其身</p> </div></body></html>
Related recommendations:
What are the methods in jQuery? Commonly used methods in jQuery (with code)
Implementation and usage of unordered image preloading in jquery
The above is the detailed content of How to implement concatenated addback() and end() in jquery (code). For more information, please follow other related articles on the PHP Chinese website!