S
S
semolex2015-03-13 11:45:50
css
semolex, 2015-03-13 11:45:50

How to use css selector to select an element that does NOT have a child element with the passed attribute?

Hey!
The next task is to specify a CSS selector in one test, which does not have a child element with a specific class.
For example, there is a set of elements

<div class='product'></div>
<div class='product'></div>
<div class='product'>
         <div class='limited'></div>
</div>

So, you need to select ALL elements of 'product' except the one containing 'limited'.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
SirMustache, 2015-03-13
@SirMustache

You can add a new class and assign it to .product blocks with no .limited children using jQuery

$('.product').each(function(e){
    if($(this).children('.limited').length < 1){
           $(this).addClass('someSpecialClass');
       }
})

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question