Replace copy package

There are two methods for replacing nodes: replaceWith() replaceAll() all means all in many places

For example, use the first replaceWith()

 

$("button").click(function(){
   $("p").replaceWith("<b>Hello world!</b>");
});

Get the button button and add a click event
Then get the p element and replace it with Hello world in the b tag

Both replaceWith() and replaceAll() methods can be used to replace elements or their content
 $(selector).replaceWith(content) and $(content).replaceAll(selector)
The parameter selector is the element to be replaced, and content is the replaced element content

All events in the element disappear after replacement

 

copy node clone()

 

$("button").click(function(){
$("p").clone().appendTo("body");
});
all <p> elements and inserted at the end of the <body> element
appendTo inserts to the end of the element
You can also use prepend to insert at the beginning of an element

 After copying the node, the new element does not have any behavior events

 

You can use the following to make him behave

 

$(this).clone(true).appendTo("body")
Passing in a parameter true in clone() means that all elements are copied while copying the events

A wrapping node is an element that can be wrapped with a label

 

There are three methods for wrapping nodes wrap() wrapAll() 

wrap()

The wrap() method wraps all elements individually

 

$("#li_1").wrap("<strong></strong>");

<strong>
  <li id="li_1" title="编程">gaofan</li>
</strong>

 wrapAll()

will wrap all matching elements in one element

$(".li_2").wrapAll("<strong></strong>");

<strong>
  <li class="li_2" title="编程">gao</li>
  <li class="li_2" title="JavaScript">lalala</li>
</strong>

 

Determine if there is a style hasClass method ()

$("button").click(function(){
alert($("p").hasClass("intro"))
})
Determine whether p uses the intro class   
Return true if any   

 There is a children() method in jquery which can traverse to find the elements you need

$("div").children(".selected").css("color", "blue")
Find all child elements of div with class name "selected" and set it to blue

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326683565&siteId=291194637