Jquery wrapInner - 排除第一个元素

标签 jquery wrapper

我正在尝试打开/折叠我的网站的部分,这些部分是带有图例标记上的单击事件的字段集。然而,我需要使用一个wrapInner在字段集中添加一个div来隐藏内容...但是这也隐藏了图例(我绝对不想这样做):-)。如何使用wrapInner但指定不隐藏图例(或者字段集中包含的第一个元素 - 因为它始终是图例)。

$("#mainarea fieldset").wrapInner("<div class='fieldsetWrapper'></div>");

$("#mainarea fieldset:not(:first)").addClass("fsClosed"); // Close all fieldsets within the main area (but not the first one)

$("#mainarea fieldset legend").mousedown(function(){  // When clicking the legend of a fieldset ...
    $("#mainarea fieldset:not(.fsClosed)").addClass("fsClosed");  // If it's already open, close it
    $(this).parent().removeClass("fsClosed");  // If it's closed, remove the closed class from the containing fieldset
    return false;
}); 

干杯 标记

最佳答案

为了回应您在 Pim 示例中的评论,您需要循环遍历字段集

$('#mainarea fieldset').each(function(){
   $(this).children().not('legend').wrapAll("<div class='fieldsetWrapper'></div>");
});

您可能可以将其重构为类似的内容;

$('#mainarea fieldset').each(function(){
   $(':not(legend)', this).wrapAll("<div class='fieldsetWrapper'></div>");
});

关于Jquery wrapInner - 排除第一个元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/459447/

相关文章:

c# - 如何制作 C# DLL COM InterOp 方法的 C++ 包装器?

java - 为输入流函数创建 java 包装器

javascript - 无论如何要对函数中定义的 javascript 函数进行单元测试?

javascript - 在 jQuery UI 日期选择器中自定义月份

javascript - 如何安全地包装 `console.log` ?

c# - 实现接口(interface)还是 double 的泛型?

C++ 编译器在使用 Bool 包装器类时报告不明确的函数调用

javascript - 如何注销设置为 jQuery.ajaxStart() 函数的处理程序?

javascript - 单击父 div 时模拟单击

javascript - 在点击功能上动画化图像,同时重叠其兄弟元素