Alternatively nodes and wrapped jQuery

Case Code:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>jQuery替换和包裹节点</title>
    <script type="text/javascript"src="../jquery-3.4.1.min.js"></script>
</head>
<body>

<div class="div">

    <</Today is Teacher's Day>= "A"the above mentioned idthe p-the p- > 
    < the p- the above mentioned id = "b" > Today is Labor Day </ the p- > 
</ div > 




</ body > 
</ HTML >

The results are:

 

 Began to replace:

 

 The results are:

 

 Fill in the html tag into a string:

 

 result:

 

 to sum up:

Replace node Keyword: replaceWith replaceAll

the difference:

1, grammar:

$ (Tag objects) .replaceWith (html);

$ (Html) .replaceAll (tag objects);

 

2, the difference between the usage restrictions:

replaceWith label or string may be used to replace

But replaceAll only use labels to be replaced

 

--------------------------------------------------------------------------------------------------

 

 

Package node:

Case Code:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>包裹节点</title>
    <script type="text/javascript"src="../jquery-3.4.1.min.js"></script>
</head>
<body>

<div class="div">
    <p>今天</p>
    <p></p>
    <p>中秋节!!</p>

</div>

<script>
    /**
     * 包裹节点的关键字以及语法
     * wrap,wrapAll,wrapInner
     *$(标签对象).wrap(标签);
     *$(标签对象).wrapAll(标签);
     * $(标签对象).wrapInner(标签);
     *
     */
  //需求:使用strong标签使div下的每个p标签的字体都变粗
    $(".div p").wrap("<srtong></srtong>")

</script>
</body>
</html>

 

 wrap结果是:

 

 使用wrapAll

 

 结果是:

 

 使用wrapInner

 

 结果是:

 

 

 

Guess you like

Origin www.cnblogs.com/bichen-01/p/11517090.html