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

jquery element wrapping

无忌哥哥
Release: 2018-06-29 14:38:35
Original
1318 people have browsed it

jquery element wrap

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>元素包裹</title>
</head>
<body>
<a href="https://www.tmall.com">天猫</a>
<a href="https://taobao.com">淘宝</a>
<a href="https://www.jd.com/">京东</a>
<a href="https://www.suning.com">苏宁</a>
<p>网上购物:</p>
<button>wrap()</button>
<button>wrapIner()</button>
<button>wrapAll()</button>
<button>unwrap()</button>
</body>
</html>
Copy after login

* 1.wrap(content):

* Function: wrap each node

* Parameter: content or element

$(&#39;button:eq(0)&#39;).click(function(){
//用法一.用一个新标签来包裹目标元素
// $(&#39;a&#39;).wrap($(&#39;<li>&#39;))
//简写:
$(&#39;a&#39;).wrap(&#39;<li>&#39;)
//用法二.用已存在的标签来包裹目标节点
// $(&#39;a&#39;).wrap($(&#39;p&#39;))
})
Copy after login

* 2.wrapInner(content):

* Function: wrap the content of each node

* Parameter: content or element

$(&#39;button:eq(1)&#39;).click(function(){
//用法一.用一个新标签来包裹目标节点内容
$(&#39;li&#39;).wrapInner(&#39;<strong>&#39;)
//用法二.用已存在的标签来包裹目标节点内容
$(&#39;li&#39;).wrapInner($(&#39;p&#39;))
})
Copy after login

* 3.wrapAll( content):

* Function: Wrap a group of nodes

* Parameters: Content or element

$(&#39;button:eq(2)&#39;).click(function(){
//用法一.用一个新标签来包裹目标节点内容
$(&#39;li&#39;).wrapAll(&#39;<ul style="background-color: wheat">&#39;)
//用法二.用已存在的标签来包裹目标节点内容,给<li>再套一个<div>
$(&#39;li&#39;).wrapAll($(&#39;<div style="background-color: cyan">&#39;))
})
Copy after login

* 4.unwrap(content):

* Function: Delete the parent element on the node

* Parameters: None

$(&#39;button:eq(3)&#39;).click(function(){
$(&#39;li&#39;).unwrap()
//可以一直往上走
$(&#39;li&#39;).unwrap().unwrap()
})
Copy after login

The above is the detailed content of jquery element wrapping. For more information, please follow other related articles on the PHP Chinese website!

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!