/    Sign up×
Community /Pin to ProfileBookmark

Changing table background with javascript

Doen’t ask why because it is a long story so this become a bit of a puzzle to solve. See the block of code below. I am trying to remove the background color of the table but I can not use the class Contents because it is affect other portions of the site.

Basically all I can come up with is using getElementByName but for some reason I am undable to get this to work. Does anyone know if this is even possible to change the background of the table without using .Contents?


______________________________________

<table bgColor=”#EEEEEE” name=”SelectedOrders” border=”0″ cellspacing=”1″ width=”100%” class=”Contents”><tr ><td width=35% align=”left” colspan=”2″ class=”Contents RegOrdPrvwLbl”>XXXX</td><td width=5% align=”right” colspan=”2″ class=”Contents RegOrdPrvwLbl”>Qty</td></tr><TR ><TD colspan=”4″ class=”Contents RegOrdPrvwLbl RegOrdPrvwLblItalic”>&nbsp;</td></tr><tr ><td colspan=”4″ align=”left” class=”Contents”>&nbsp;</td></tr></table>


______________________________________

to post a comment
JavaScript

8 Comments(s)

Copy linkTweet thisAlerts:
@KorJun 27.2008 — A table must not bear a name, but an [B]id[/B]. If you can not use the class nor give it an id, than find something which is specific to that table. How many tables do you have on the document. Is this the first, second, third ... table? Or?
Copy linkTweet thisAlerts:
@kpikulauthorJun 27.2008 — This table I am trying to access is embedded 6 table deep.

<table.Contents><table.Contents><table.Contents><table.Contents><table.Contents><table.Contents <!--this is the table-->>
Copy linkTweet thisAlerts:
@KorJun 27.2008 — document.getElementsByTagName('table')[5].style.backgroundColor='#ff0000';
Copy linkTweet thisAlerts:
@kpikulauthorJun 27.2008 — PERFECT!!!! Thank you
Copy linkTweet thisAlerts:
@kpikulauthorJun 27.2008 — Do you know why this does not work in Firefox on a Mac. It works with Firefox on a PC.

document.getElementsByTagName('table')[5].style.backgroundColor='#ff0000';
Copy linkTweet thisAlerts:
@kpikulauthorJun 27.2008 — nevermind, my bad. typo.
Copy linkTweet thisAlerts:
@kpikulauthorJun 27.2008 — The problem I am having now is that it is not always the 5th table depending how the application renders the site.
Copy linkTweet thisAlerts:
@KorJun 30.2008 — You [I]need[/I] something to distinguish that table from others. If it is not always the 5th, then what could be? A distinct class? An id? A distinct attribute? Which? Find something which appears [I]always[/I] HTML on that table, and [I]never[/I] on the others.
×

Success!

Help @kpikul spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.25,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...