Home  >  Article  >  Web Front-end  >  jquery element wrapping

jquery element wrapping

无忌哥哥
无忌哥哥Original
2018-06-29 14:38:351320browse

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>

* 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;))
})

* 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;))
})

* 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;))
})

* 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()
})

The above is the detailed content of jquery element wrapping. 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