tags:

views:

55

answers:

3

Theres a mistake in my rather large demo where i assume all the divs under the class special will be used to align something. Now i realize i need to add an extra div outside of the part i want to align but inside of .special.

How do i write .special div[NOT someclass] ? or is there no way to do this and i need to rewrite a lot of html?

+1  A: 

I would go with jQuery or some other Javascript Framework, the selectors just rock and NOT class XY is rather easy to achieve. As Pekka pointed out I am not sure what brothers you want to target. getElementsByClassName() is implemented by almost all browsers (you know which one doesn't work, don't you?).

I found a rather nifty solution on devshed to also make it work in IE:

onload=function(){
if (document.getElementsByClassName == undefined) {
    document.getElementsByClassName = function(className)
    {
        var hasClassName = new RegExp("(?:^|\\s)" + className + "(?:$|\\s)");
        var allElements = document.getElementsByTagName("*");
        var results = [];

        var element;
        for (var i = 0; (element = allElements[i]) != null; i++) {
            var elementClass = element.className;
            if (elementClass && elementClass.indexOf(className) != -1 && hasClassName.test(elementClass))
                results.push(element);
        }

        return results;
    }
}
}

All you need to do now is to iterate through all your div classes and negate the one you DON'T want.

moontear
Hehe... "I am not sure what brothers you want to target". I'd give you a humor upvote if such a thing existed :)
Šime Vidas
`typeof x == 'undefined'` is better than `x == undefined` because `undefined` is just a global variable that can be set to anything, but `typeof` is a keyword that always returns the correct string.
casablanca
@Šime whoops... I'll leave it as it is for future fun @casablanca I always went with the latter, but your explanation tells me there is a better way. Thanks!
moontear
+1  A: 

CSS3 includes the not() selector. The only problem is (you guessed it) no IE compatibility. If you're willing to require Javascript from IE <9 users, you can get IE compatibility with IE9.js.

Chuck
A: 

+1 to both answers above. I'll add i was able to get away with some things but writing this in the css block to undo the effect

some-type: inherit;
acidzombie24