Skip to content Skip to sidebar Skip to footer

CSS Selector (or JavaScript If Needed) For Select DIV's Which Contain At Least One UL

Suppose I have a hierarchy like this:
Copy

Note: If you are using some dynamic language on the server, such as PHP, this could actually be implemented fairly easily, without manual coding.

Or if you want to be dynamic I recommend jQuery:

$("div > ul").parent().addClass("div_with_ul_class");

Solution 2:

Parent selector isn't available in CSS, despite a lot of requests to add it.

jQuery has a nice selector, know as :has; http://api.jquery.com/has-selector/

$('div:has(ul)');

Would be the jQuery selector.


Post a Comment for "CSS Selector (or JavaScript If Needed) For Select DIV's Which Contain At Least One UL"