[thelist] Javascript: altering BG color of multiple divs with one click - solved

Dunstan Orchard dunstan at 1976design.com
Tue Nov 11 14:11:13 CST 2003


On Tue, 11 Nov 2003 14:44:11 -0500, Hershel Robinson wrote
> Not sure why you find this odd. Most languages require the keyword if before
> an if/else statement.

Doh!

Sorry, typos galore!
I meant:

if (i = 0)

crashed my browsers, while this:

if (i != 0)

doesn't. So I had to swap the logic around a little bit.

_That_ I find odd :o)


> I would actually clean up the above code to this:
> for (var i = 0; i < relatedItems.length; i++)
> document.getElementById(relatedItems[i]).className = (i != 0) ? "question"
> : "answer"

Ah, much nicer, I forgot about that.

Thanks again - Dunstan

---------------------------
Dorset, England
http://www.1976design.com/
http://www.1976design.com/blog/


More information about the thelist mailing list