/    Sign up×
Community /Pin to ProfileBookmark

weird color behaviour with javascript

Hi,

can somebody tell why i got back an empty string, when i want to access the color property of a html-Element like this:

[CODE]<?xml version=”1.0″ encoding=”iso-8859-1″ ?>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN”
“http://www.w3.org/chtml1/DTD/xhtml1-strict.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<title>Test</title>
<meta http-equiv=”content-type” content=”text/html; iso-8859-1″/>

<style type=”text/css”>
/*<![Cdata[ */
p {
color: green;
}
/*]]> */
</style>

<script type=”text/javascript”>
/* <! [Cdata[ */
window.onload = function() {
BUG.DOMLoaded = true;
BUG.feed(‘calling window.onload’,2);

BUG.feed(‘Color: ‘+typeof document.getElementById(‘test’).style.color,2);
BUG.feed(‘Color: ‘+document.getElementById(‘test’).style.color,2);
}
/* ]]> */
</script>

</head>
<body>

<h1>Test</h1>

<p id=”test”>text</p>
</body>

</html>[/CODE]

The typeof tells me the type of the property is string, but if i print it out its empty, why?

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@gil_davisOct 31.2007 — The typeof tells me the type of the property is string, but if i print it out its empty, why?[/quote]
The "typeof" rightly identifies it as a string, even if it is empty. For some reason javascript does not reveal properties set by a stylesheet. I think it is an aggregious bug.
Copy linkTweet thisAlerts:
@KravvitzOct 31.2007 — It's not a bug. The style object is the interface for accessing the style attribute of each element.

Check out [url=http://www.quirksmode.org/dom/getstyles.html]Get Styles[/url].

P.S. The XML declaration (the line above the doctype) forces IE6 into quirks mode, which is usually a bad thing. (They fixed that bug in IE7.)
×

Success!

Help @jens1701 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.18,
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,
)...