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');
is there a more direct way?
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');
is there a more direct way?
You can simplify your code to:
$('div:has(> object)').css('text-align', 'center');
Use the :has
selector:
$("div:has(> object)").css("text-align", "center");
Here's an example I wrote up:
$(function() { $("div:has(> h3)").css("background", "yellow"); });
div { padding: 15px; border: 1px solid black; }
outer
inner