我希望得到所有具有内联风格的元素,并在div和他所有的孩子中搜索它。例
<div id="idofstartdiv">
<span style="color:red;"></span>
<div>
<div style="color:green"><span style="color:yellow;"></span><span></span></div>
</div>
</div>
我知道我可以通过$("[style]")
得到所有的内联风格,我知道选择$("#idofstartdiv")
的起始div。
我怎样才能将这两个选择器结合起来?
非常感谢。
你可以简单地做到:
$("#idofstartdiv[style]")
这将获得id为idofstartdiv
的元素以及style
属性。要使所有具有style
属性的id的父级作为父级,您可以执行以下操作:
$("#idofstartdiv").find("[style]")
如其他答案中所述,您还可以:
$("#idofstartdiv [style]")
$("#idofstartdiv [style]") is this is what you are asking for? if not can you provide an example of what you are expecting, am not clear with your question.
另一种选择 -
$("[style]", "#idofstartdiv")
这也将返回父div-id“idofstartdiv”下具有style属性的所有元素。