Tring to obtain attribute of li element that had values set with css

T

Terry

Hi folks.

I was wondering why it seems that I can't obtain the properties that
have to been assigned to a tag through use of css.


For example if I have:

css:


#theli {
display:inline;
background-color: green;
padding-left:10px;
padding-right:10px;
}


html:

<li id="theli">Hi there</li>


And I have in a javascript function that is called when the page is
loaded:


alert("color = " +
document.getElementById("theli").style.backgroundColor);
document.getElementById("theli").style.backgroundColor = "black";
alert("color = " +
document.getElementById("theli").style.backgroundColor);


The first alert only shows color = (with nothing else)


while the second alert shows color = black


Any ideas as to why I don't see green at the end of the first
color: ?

the url to my page is http://restaurant.atwebpages.com/contactus.htm
 
G

Gregor Kofler

Terry meinte:
Hi folks.

I was wondering why it seems that I can't obtain the properties that
have to been assigned to a tag through use of css.
#theli {
display:inline;
background-color: green;
padding-left:10px;
padding-right:10px;
}

You haven't defined the color.
The first alert only shows color = (with nothing else)

Makes sense.
while the second alert shows color = black

This as well.
Any ideas as to why I don't see green at the end of the first
color: ?

Because color != backgroundColor.

Still markup with errors...

Gregor
 
J

John Hosking

Gregor said:
Terry meinte:

Even having read the exchange here, I don't get it. One more time,
please, for us slower children.
You haven't defined the color.

I, too, see this to be true. I claim that Terry has defined the
background-color, namely to green. Yes?
Makes sense.

Not if the code is indeed really detecting the background-color. The
text prompt is only some letters. The claimed code is

alert("color = " +
document.getElementById("theli").style.backgroundColor);

which might as well be

alert("Jamaican elephants with chopsticks = " +
document.getElementById("theli").style.backgroundColor);
This as well.

Well, it (really the BG color) was just set to black.

document.getElementById("theli").style.backgroundColor = "black";
alert("color = " +
document.getElementById("theli").style.backgroundColor);
Because color != backgroundColor.

Obviously I'm missing something obvious.

which code includes something like .clientbackgroundColor, which seems
like some intermediate test attempt, not related to the above problem.

Type slowly so I get it, please.
 
T

Terry

Okay folks.

It seems that the last poster did notice that I made some changes to
the javascript as well as the stylesheet.

Unfortunately, I still cannot obtain the color value nor can I obtain
the paddingLeft value unless its seems that I set them with javascript
and then try to obtain them. What I really am trying to do is obtain
the values as they were set with css.

The html as well as the css has been validated.

The url to the page is http://restaurant.atwebpages.com/contactus.htm
 
J

John Hosking

Terry said:
Okay folks.

It seems that the last poster did notice that I made some changes to
the javascript as well as the stylesheet.

Just a vague, uninformed guess: Case sensitivity? color / Color?
 
T

Terry

According to The Definitive Guide, what Terry is trying to do only works
for inline CSS styles and JavaScript set styles. There was a recent
discussion on this. Search for "getComputedStyle".

Thanks Dave.

Is the definitive guide a book or a website.
 
J

John Hosking

Cool. I should pay closer attention. I've never tried to do this
(Terry's task) before.
Thanks Dave.

Is the definitive guide a book or a website.

It's not only your access point for Usenet, Google is also your friend:
http://www.amazon.com/JavaScript-Definitive-Guide-David-Flanagan/dp/0596101996

Also, if you actually lurk here a bit, you'll see the author and his
work mentioned (sometimes disparagingly), e.g. in the thread "FAQ Update
9.85 Dated 2007-08-31": http://www.davidflanagan.com/
 
T

Thomas 'PointedEars' Lahn

Dave said:
According to The Definitive Guide, what Terry is trying to do only works
for inline CSS styles and JavaScript set styles. There was a recent
discussion on this. Search for "getComputedStyle".

On a side note, I find it really strange for a book to call itself
"JavaScript: The Definitive Guide" whose author is not able to get the
language basics right, but dares to make comments on specific DOM support.
As if the DOM was still a part of the programming language like in the bad
old days, before JavaScript version 1.4.

Unless there is another "The Definitive Guide" to state the above that I am
not aware of.


PointedEars
 
D

Dr J R Stockton

In comp.lang.javascript message <[email protected]
glegroups.com>, Mon, 3 Sep 2007 19:25:58, Terry
Is the definitive guide a book or a website.

The newsgroup FAQ should render such questions unnecessary. Read it.

But a Google search for '"The Definitive Guide"' finds 1.7 million
entries, the second entry answering your question. Search for '+"The
Definitive Guide" +javascript' finds only 1.1 million.

Search for '+"The Definitive Guide" -javascript' finds nearly
1.7 million, which casts some doubt on the counting.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top