- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有两个变量 currentSectionElement
和 sectionList
。
它们看起来像:
currentSectionElement = $("<div>current</div>");
sectionList = $("<div>sectionList</div>");
我想这样显示:
<div>
<div>current</div>
<div>sectionList</div>
<div>
所以,我尝试了以下方式:
currentSectionElement.after(sectionList);
$(currentSectionElement, sectionList).wrapAll('<div></div>');
但是它变成了:
<div>
<div>current</div>
<div>
<div>sectionList</div>
最佳答案
您可以使用 .add()
将 currentSectionElement
和 sectionList
组合成一个 jQuery 对象,然后使用 .wrapAll()
var currentSectionElement = $("<div>current</div>");
var sectionList = $("<div>sectionList</div>");
var newObj = currentSectionElement.add(sectionList);
newObj.wrapAll('<div></div>').parent().appendTo(document.body);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
您可以创建另一个 div
并使用 append()
var currentSectionElement = $("<div>current</div>");
var sectionList = $("<div>sectionList</div>");
var newObj = currentSectionElement.add(sectionList);
$('<div>').append(newObj).appendTo(document.body);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
关于javascript - jQuery wrapAll 带变量的两个元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39326332/
我试图用另一个元素包装动态创建的一系列生成元素,例如: var innerHtmlAsText = "test1test2"; var wrapper = ""; $("div#target").ap
有一些 HTML 看起来像这样: Do all declarations for the same static function or vari
我坚持尝试将 3 个 div 封装在一个包装 div 中。到目前为止,我已经成功地完成了 2 个 div,但我无法弄清楚最后一个。 你可以在这里看到我的 JSFiddle:http://jsfiddl
我正在使用这个脚本来包装两个 div: jQuery: $("#wrapcb").click(function(){ $('#cboxOverlay, #colorbox').wrapAll(''
我有一组生成的 div 宽度相同的类,其中包含标题和一系列链接。由于某种原因,末尾有一个隐藏的 header 。 它们看起来像这样: List Header List item Li
考虑这段代码: var n = 5; // NOTICE THIS LINE!! $(function() { var $newDiv = $("#content > .post:gt(5)").w
假设这是我的 HTML 现在我想将 .product-thumbnail 和 .product-price 包装在 像这样
我正在使用 stackoverflow 上的一位成员建议的一些代码,并由我进行修改,将每 3 个列表项包装为大型菜单的一部分。代码是: var lis = $("ul > li"); for(var
考虑以下代码:(实例 here ) $(function() { var wrapper = $(""); $(".a").wrapAll(wrapper); wrapper.css("b
请看一下下面的 fiddle : http://jsfiddle.net/ardoramor/UzJqd/ 当 fiddle 加载时,带有 .wrapper 类的 DIV 向下滚动 200px。这包括
用 jQuery 包装 div 后,展开它们然后尝试再次包装它们似乎会丢失 float 属性(我的猜测),我不知道如何解决这个问题。 当第一次按下 JSFiddle 中的换行按钮时,它会像我期望的那样
如何确保所有带有 .px-sub-menu-item 的类都包含在一个 div 中? (function($) { $('.px-sub-menu-item').each(function() {
我有两个变量 currentSectionElement 和 sectionList。 它们看起来像: currentSectionElement = $("current"); sectionLis
我看到有 wrap() 的回调以及 wrapInner()但我注意到 wrapAll 没有回调函数. 这是否意味着操作以同步方式而不是异步方式发生? 如果我这样做是正确的吗? $('.test').w
我需要将三个 div 合并为一个,但是这三个 div 在代码中重复了好几次。也许我的 HTML 会解释: 我想要实现的是: 这是将所有内容包装到
我有一个容器 div,里面有两个 div,像这样: 我在“child1”和“child2”周围包裹了另一个 div,但它出现了两次,我无法修复: $(".child1, .child2
我的标记如下所示: 我希望事情是这样的: 因此我可以填充 #isolated
我需要找到所有 div 中具有 someClass 类的所有 p 标签,并将它们用另一个 div 包装。开始标记如下所示: // Lots of different tags generated
我有一系列 DIV,它们根据大小分配了 .big 或 .small。它们需要以两到三个为一组进行包装。实际上,分配的空间只能容纳两个 .big。 如果两个 .big DIV 彼此相邻存在,则应将它们分
我有这个 date-picker 框,我使用 wrapAll 添加了一个日历图像,下图是结果: 这是我的代码: $(function() { $(".date-picker").datepicke
我是一名优秀的程序员,十分优秀!