繁体   English   中英

选择只有一些元素的孩子

[英]select the children with only some elements

我想选择某些元素的子元素,而拒绝其他元素。

请参考下面的HTML。

    <g id="container_svg_SeriesGroup_0" transform="translate(77,465)">
    <defs>
<linearGradient id="container_svg_symbol0Gradient" x1="0%" y1="0%" x2="0%" y2="600%"><stop offset="0" stop-color="gray" stop-opacity="1"/><stop offset="0.5" stop-color="blue" stop-opacity="1"/>
</linearGradient>
</defs>
<path id="container_svg_rectsymbol0" fill="url(#container_svg_symbol0Gradient)" stroke-width="1" stroke="Gray" d="M -5 -450 L 5 -450 L 5 -440 L -5 -440 L -5 -450"/>
<defs>
<linearGradient id="container_svg_symbol1Gradient" x1="0%" y1="0%" x2="0%" y2="600%"><stop offset="0" stop-color="gray" stop-opacity="1"/><stop offset="0.5" stop-color="blue" stop-opacity="1"/></linearGradient>
</defs>
<path id="container_svg_rectsymbol1" fill="url(#container_svg_symbol1Gradient)" stroke-width="1" stroke="Gray" d="M 73.1111111111111 -71.75 L 83.1111111111111 -71.75 L 83.1111111111111 -61.75 L 73.1111111111111 -61.75 L 73.1111111111111 -71.75" transform="scale(1)"/>
...................
</g>

我想选择该组“ container_svg_SeriesGroup_0”的子级,但不选择“ defs”组。 我想找到其他元素而不是“ defs”

我尝试如下

$("#container_svg_SeriesGroup_0").children("path")

它返回路径元素。 但是在“我的DOM”中,任何类型的元素都将放置在该组“ container_svg_SeriesGroup_0”中

因此,我只是不选择“ defs”组,而是选择其他元素直接控制该组的子级。

期望像在jQuery中使用“ .not”选择器那样的答案。

谢谢,

西瓦

尝试这个 :

  $('#container_svg_SeriesGroup_0 > :not(defs)');

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM