jQuery | wrapAll()及其示例

wrapAll()方法是jQuery中的一个内置方法,当指定的元素将针对所有选定的元素进行包装时,会使用该方法。

null

语法:

$(selector).wrapAll(wrap_element)

参数: 此方法接受单个参数 包裹元素 这是强制性的。此参数用于指定将哪个元素包裹在选定元素周围。

返回值: 此方法返回所选元素,其中包含wrapAll()方法所做的指定更改。

下面的示例演示了jQuery中的wrapAll()方法:

例子:

<!DOCTYPE html>
< html >
< head >
< title >The wrapAll Method</ title >
< script src =
</ script >
<!-- jQuery code to show the working of this method -->
< script >
$(document).ready(function() {
$("button").click(function() {
$("p").wrapAll("< div ></ div >");
});
});
</ script >
< style >
div {
background-color: lightgreen;
padding: 20px;
width: 200px;
font-weight: bold;
height: 60px;
border: 2px solid green;
}
</ style >
</ head >
< body >
<!-- click on this paragraph and see the change -->
< p >Welcome to GeeksforGeeks!< br >< br >
< button >Click Here!</ button ></ p >
</ body >
</ html >


输出: 图片[1]-jQuery | wrapAll()及其示例-yiteyi-C++库

© 版权声明
THE END
喜欢就支持一下吧,技术咨询可以联系QQ407933975
点赞15 分享