选择一个具有另一个元素作为直接子元素的元素 [英] Selecting an element which has another element as direct child
本文介绍了选择一个具有另一个元素作为直接子元素的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要选择所有包含object
的div
作为其直接子代. :has
只是检查任何后代,所以现在我在使用:
I need to select all div
s which contain object
as their direct child. :has
just checks for descendants of any kind, so now I'm using:
$('div > object').parent().css('text-align', 'center');
还有更直接的方法吗?
推荐答案
您可以将代码简化为:
$('div:has(> object)').css('text-align', 'center');
这篇关于选择一个具有另一个元素作为直接子元素的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文