/    Sign up×
Community /Pin to ProfileBookmark

RGB not HTML???

Hey guys!

I inplicitly set the background-color of a paragraph using the style attribute at the beginning of a page.

Now in a function, I want it to flash, so I used:

[code]
(bar.style.backgroundColor==”#000000″)?bar.style.backgroundColor=”#ffffff”:bar.style.backgroundColor=”#000000″;
[/code]

…inside a setInterval statement, and it wasn’t working.

I then decided to: alert(bar.style.backgroundColor==”#000000″), and it came back with “rgb(0,0,0)”.

Why rgb, when there isn’t even a javascript rgb() function?

Thanks.

CM

to post a comment
JavaScript

7 Comments(s)

Copy linkTweet thisAlerts:
@UltimaterApr 21.2006 — Firefox will convert your colors into the RGB format while IE will not. So it is adviced to use the RGB format within CSS to the set color. When you alert the color then, you'd still have a problem with spaces between the two browsers which can be easily resolved via replace(/ /g,''). Another solution is to test if "#" appears in the color or "rgb(" appears in the color.
Copy linkTweet thisAlerts:
@CharlesApr 21.2006 — In DOM level 1 you're not supposed to monkey with styles and I tend to think that this is a good restrictyion. Better to swap the className.
Copy linkTweet thisAlerts:
@BuilderQApr 21.2006 — And Opera will convert colors into hex format. ?
Copy linkTweet thisAlerts:
@UltimaterApr 21.2006 — The best method would be className swapping as Charles stated.
And Opera will convert colors into hex format. ?[/QUOTE]
I haven't messed around with Oprea enough so I wouldn't know... If so, it wouldn't make a difference if you use the hex color format or the rgb color format in CSS and it would support Charles's DOM1 statement about messing with styles. Might have to resort to testing, if classes isn't an option nor rememering what the color is in a variable. Could always make a className for each and every color ?
Copy linkTweet thisAlerts:
@CrazyMerlinauthorApr 21.2006 — thanks.

I just didn't think of classname swapping in this situation.

Thanks again guys!
Copy linkTweet thisAlerts:
@CharlesApr 21.2006 — Do be careful. It's "className" and not "classname".
Copy linkTweet thisAlerts:
@felgallApr 21.2006 — Different browser return the color and backgroundColor using different formats so if you want to test for them you need to test at least three different alternatives. Changing className is probably easier in most instances.
×

Success!

Help @CrazyMerlin 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.6,
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,
)...