[thelist] Tip: Avoiding unnecessary loops by harnessing the CSS cascade

Christian Heilmann codepo8 at gmail.com
Tue Mar 14 05:16:50 CST 2006

I just realised that:

<tip type="JavaScript, DOM scripting, CSS" author="Chris Heilmann">
Many times when you create a new script you tend to loop too much,
which slows down the script and is prone to errors when the HTML is
not that clean.

A typical case is looping through every element you want to hide and
apply a "hiding" class to it. Instead, it is much shorter and cleaner
to simply apply one class to the parent element of all the others and
use the CSS to hide all elements via the contextual selector.

Check the example with some code to back up the train of thought:

Chris Heilmann
Blog: http://www.wait-till-i.com
Writing: http://icant.co.uk/
Binaries: http://www.onlinetools.org/

More information about the thelist mailing list