On Apr 14, 2008, at 4:29 PM, Bill Brown wrote: > John wrote: > [snip] >> This has been an excellent thing for me to learn in my >> greenhorn-hood.. >> >> As I adjust my pages to work with this new combined style sheet, I'm >> adding "id="index" to every instance of my <p> tags; my "space >> after" design employs a <p>paragraph's worth of text</p> >> <p>paragraph's worth of text</p>, so every <p> needs adjusting. >> >> Is there a way to say "All of these <p> are now <p id="index">?" > [snip] > > Hi John, > > If it was me, I'd change them to classes and then use a Javascript > function to change any non-index-class <p>s into <p class="index"> > with > a little javascript like this: > > var convertParasToIndexParas = function () { > var allParas = document.getElementsByTagName("P"), > i = allParas.length; > while (i--) { > if (allParas[i].className.indexOf("index")<1) { > allParas[i].className = allParas[i].className + " index"; > } > }; > }; > window.onload=convertParasToIndexParas; > > Ideally, the window.onload function should be routed through an Event > Manager (google:addEvent). I like Dean Edwards' solution for this.
I would strong advise against something like this just to add a css class to all instances of an element on a page. When you do something like this, you should be taking advantage of what CSS was meant for: cascading. It's also a bunch of unnecessary javascript that will be run on every page load. I'd recommend attaching a class to a parent container (usually the body tag or a wrapper div) called 'index' and use css to style your p's: <body class="index"> <p>here's my text</p> </body> .index p { //styles here } This is similar to other replies on this thread. Ryan Doherty [EMAIL PROTECTED] ______________________________________________________________________ css-discuss [EMAIL PROTECTED] http://www.css-discuss.org/mailman/listinfo/css-d List wiki/FAQ -- http://css-discuss.incutio.com/ List policies -- http://css-discuss.org/policies.html Supported by evolt.org -- http://www.evolt.org/help_support_evolt/