jQuery使用.not()排除部分内容
上面是jQuery的一部分,用于查找类,但不包括jQuery使用.not()排除部分内容,jquery,Jquery,上面是jQuery的一部分,用于查找类,但不包括.tabs,它是.woocommerce tabs元素的子元素 但是,.tabs仍然显示在输出中,这不是我想要的 示例html输出 .find('.woocommerce-tabs').not('.tabs').html(); 产品说明 健壮的 连续360°转台旋转 补充资料 轮胎(泡沫填充) 16“ 重量(千克) 6950 试试看 .not(':has(.tabs)不选择包含类为tabs的元素的元素您的代码过滤不包含选项卡的元
.tabs
,它是.woocommerce tabs
元素的子元素
但是,.tabs
仍然显示在输出中,这不是我想要的
示例html输出
.find('.woocommerce-tabs').not('.tabs').html();
-
-
产品说明
- 健壮的
- 连续360°转台旋转
补充资料
轮胎(泡沫填充)
16“
重量(千克)
6950
试试看
.not(':has(.tabs)
不选择包含类为tabs的元素的元素您的代码过滤不包含选项卡的元素
类名,它不会从html输出中排除指定的元素。您可以.clone()
元素,删除子体,然后调用.html()
方法
.find('.woocommerce-tabs').not(':has(.tabs)').html();
一种方法是克隆.woocommerce选项卡
并从克隆元素中删除.tabs
.find('.woocommerce-tabs').clone().find('.tabs').remove().end().html();
然后,您可以在代码中使用克隆的html
:
var clone = $'.woocommerce-tabs').clone();
clone.find('.tabs').remove();
var html = clone.html();
你可以发布它的html吗?@Joseph添加了html示例
var clone = $'.woocommerce-tabs').clone();
clone.find('.tabs').remove();
var html = clone.html();
.find('.woocommerce-tabs').not('.tabs').html(html);