Use JavaScript to change foreground and background color across the page?

Here is a sample script for changing background color on page load for all "divs" that have background color style. The approach would be needed for all other types of elements that for which background color need to be changed.

I modified this a little and it worked like a charm :) – Ravi Vyas Dec 8 at 9:06 Although I lost color on the link :) – Ravi Vyas Dec 8 at 12:52.

It is possible. You can get all the elements within the wrapper div with by calling wrapper. GetElementsByTagName("*") (wrapper being the wrapper element).

Depending on the size of the site, that could be slow.

Yes, you could do something involving a two step approach whereby first you select all the target elements using an appropriate selector (e.g. "getElementById()" and "getElementsByTagName()") and then set their colors via the style attribute. For example: // Select all elements whose color must be changed. Var els = ; els.

Push(document. GetElementById("item1")); els. Push(document.

GetElementById("item2")); els. Push(document. GetElementById("item3")); // And so on... // Set their new foreground and background colors.

For (var i=0; iColor = 'black'; // New foreground color. Elsi.style. BackgroundColor = 'white'; // New background color.

} Also, consider using a JavaScript library such as jQuery with rich selector functionality; this could drastically simplify the first step.

I wouldn't advise HTML5's getELementsByClassName() yet. Depends on your audience though. – Jeffrey Sweeney Dec 7 at 14:51 @JeffreySweeney: ah, thanks, I didn't realize that was an HTML5 addition, I'll refine my answer so it's not dependent on that feature.

– maerics Dec 7 at 15:10 The HTML an be anything and I would not be aware of the elements. – Ravi Vyas Dec 8 at 6:16.

I would strongly recommend using wrapper. GetElementsByTagName("*").style. BackgroundColor = "purple";.

This seems like the best solution given your constrains. Yes, getElementsByTagName("*") is going to be slow, but given that this is going to be on an Android device I believe it can easily handle this.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions