【发布时间】:2011-05-09 15:36:38
【问题描述】:
我当然知道如何在每次进行选择时将 jQuery 选择器限制为特定元素的子元素(即 $('#left ul') 选择所有属于 #left 的子元素的 ul)。虽然这很简单,但如果我要对#left 的各个子节点执行一堆操作,则必须继续编写 $('#left ul')、$('#left p')、 $('#left ...').相反,我更愿意暂时将潜在的选择器限制为#left 的唯一子级。例如:
...some code that established #left as the "scope" of any future selectors;
$('ul').css(...); //actually selects $('#left ul')
$('p').css(...); //actually selects $('#left p')
...some code that re-established the full DOM as the "scope";
$('ul').css(...); //selects all ul, not just children of #left
$('p').css(...); //selects all p, not just children of #left
谢谢!
【问题讨论】:
标签: javascript jquery dom css-selectors