Your given code won't have the intended effect, even if you were to use jQuery.
The not
method in jQuery filters the set of matched elements to exclude those which match a condition. Example $(".animal").not(".dog")
originally matches any animal, and then is filtered to exclude dogs. The effective jQuery object at the end of the filtering would still include other animals, but would no longer include dogs. This does not do any DOM tree searches, and does not consider descendants. The selector is applied to each element in the original matched set, and the element is excluded if it matches.
The correct way (jsFiddle), in your example, to highlight all the child <div>
s except the news, is to select all the child <div>
elements, then filter:
$('#outerdiv > div').not('.news').css('background-color', 'red');
To reproduce this in (non-framework-augmented) JS, try (jsfiddle):
var divs = document.querySelectorAll('#outerdiv > div:not(.news)');
for (var i=0; i < divs.length; i++) {
divs[i].style.backgroundColor = 'red';
}
The :not()
pseudo-element selector is a CSS 3 selector which filters matched elements. It is more limited than jQuery's .not()
however, and it only allows certain selectors to be nested inside it. From the MDN docs:
The negation CSS pseudo-class, :not(X), is a functional notation taking a simple selector X as an argument. It matches an element that is not represented by the argument. X must not contain another negation selector, or any pseudo-elements.