javascript - 如何(wrapInner 或 wrapAll)排除第一个 div 类

标签 javascript jquery css html

enter image description here

我想包装“name portlet-title”下面的所有元素但是,不应该包括下面“div class name portlet-title”中的其他元素。我尝试了以下方法:

1) $("div.item").wrapAll('<div class="portlet-body"></div>');

它正在影响页面中的所有元素。

2) $("div.list").wrapInner('<div class="portlet-body"></div>');

它包括“div 类名 portlet-title”

我不太擅长 jquery,请帮助我。

最佳答案

您需要使用一个循环,以便您可以单独对元素进行分组。

$('.list.portlet').each(function(){
    $(this).find('div.item').wrapAll('<div class="portlet-body"></div>')
})

关于javascript - 如何(wrapInner 或 wrapAll)排除第一个 div 类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20659291/

相关文章:

html - 在 Logo png 图像旁边放置文本

html - 网页不总是正确定位?

javascript - AngularJS 起源 http ://localhost:8080 is not allowed by Access-Control-Allow-Origin

javascript - 滚动背景过渡在 Chrome 和 IE 上产生链式 react

javascript - parseInt(x,10) 导致最大调用堆栈/太多递归错误

javascript - 循环内循环产生错误结果

javascript - 选项 "setupTestFrameworkScriptFile"被配置 "setupFilesAfterEnv"取代,它支持多路径

django - 我如何将 django dajax 框架与 jquery ajax 事件一起使用

php - Jquery 移动 HTTPS 失败

html - 删除 HTML 电子邮件中表格行之间的间距