- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个内容,其中包含许多 TextNodes、段落和图像。我想将所有图像标签放在父 div 中。嗯,我认为没有直接的方法可以做到这一点(我的意思是在 jQuery 中)。我应该如何处理元素的这种位移。下面的例子说明了我的意图:
原始内容:
<div id='content'>
Here are some texts.
A second line.
<a href='http://google.com'>Click Here!</a>
Another Line.
<img src='image.jpg' />
Another another line.
<img src='secondImage.jpg' />
Last line and many more to come.
</div>
处理后:
<div id='content'>
Here are some texts.
A second line.
<a href='http://google.com'>Click Here!</a>
Another Line.
<div class='image-parent'>
<img src='image.jpg' />
</div>
Another another line.
<div class='image-parent'>
<img src='secondImage.jpg' />
</div>
Last line and many more to come.
</div>
唯一不同的是,现在每个图像都被一个新的 div 包裹着。
最佳答案
使用.wrap()
将 HTML 结构包裹在每个元素周围。
$("#content > img").wrap("<div class='image-parent'></div>");
.image-parent {
border: 1px solid red;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id='content'>
Here are some texts.
A second line.
<a href='http://google.com'>Click Here!</a>
Another Line.
<img src='image.jpg' />
Another another line.
<img src='secondImage.jpg' />
Last line and many more to come.
</div>
关于javascript - 将元素包装在新元素的原处,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38324803/
我正在用 Java 编写代码,并且使用 Vaadin 8 扩展。 我有一个 Vaadin 组合盒,效果很好。但我不仅想从组合框中选择项目,还想选择书面输入。这意味着我想使用组合框作为下拉菜单以及文本编
我正在尝试将 AJAX 添加到 JQuery ListView 中并呈黄色闪烁,但我似乎无法使其正常工作。谁能指出我正确的方向? http://jsfiddle.net/zFybm/ 最佳答案 根据
我有这个样式表: .pixel{ position: absolute; height: 10px; width: 10px; background-color: #f
这是我用来将新行推送到容器的一行代码: this.$el.append(new ItemView(item).render().el); 其中item是Backbone.js model,render
我正在尝试在 anguar.js 中制作一些测试应用程序,但遇到了问题。我的 js 文件包含: live = angular.module('live',[]); live.controller('p
如何绑定(bind)页面加载后创建的新元素? 我有这样的东西 system = function() { this.hello = function() { alert
html5 新元素(页眉、导航、页脚等)在 IE 中不工作 最佳答案 您需要包含 HTML5 shiv 脚本以允许在旧版 IE 浏览器中设置 HTML5 元素的样式:http://code.googl
我是一名优秀的程序员,十分优秀!