Home  >  Article  >  Web Front-end  >  How to implement concatenated addback() and end() in jquery (code)

How to implement concatenated addback() and end() in jquery (code)

不言
不言Original
2018-08-13 17:14:451569browse

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 is the difference between v-if and v-show in vue? Summary of the differences between v-if and v-show

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!

Statement:
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