Home > Web Front-end > JS Tutorial > body text

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

不言
Release: 2018-08-13 17:14:45
Original
1592 people have browsed it

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>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template