Scripting: Retrieving css values via javascript

started by David on Jan 15, 2005 — RSS Feed

David David
Posts: 40

Hi guys,

I know you can change CSS values by using:

var doodhah = document.getElementById('name')
doodah.style.value = 'value'


But what do I do if I want to find out what the value of doodah.style.value already is?

Joe Gillespie Joe Gillespie
Posts: 528

Try

var dsv=doodah.style.value

David David
Posts: 40

hmm, that didn't work.

I also tried putting it into a function but that didn't work either.  I'll paste the relevant code below.  (For the time being I've put the values directly into the script but I changed the first element in the array to show what I'd like to do).

var homeInfo = document.getElementById('home');
     var homeBgCol = homeInfo.style.backgroundColor;

     bgCol[1] = [homeBgCol];
     bgCol[2] = ['#aa7a00'];
     bgCol[3] = ['#dab372'];
     bgCol[4] = ['#bc8860'];


If I examine the js console in Firefox I get told:

Error: homeInfo has no properties.

Of course, it does have properties and the same code works fine elsewhere in the script.  The relevant css is reproduced below:

#home
{
 position: absolute;
 height: 1.1em;
 width: auto;
 margin-top: 1em;
 margin-left: 0px;
 margin-right: 0px;
 background-color: #ca7e02
}

Baxter Baxter
Posts: 157

I'm pretty dim when it comes to js, but I think you want background instead of backgroundcolor, and I think you need something after background to refer to the array.

David David
Posts: 40

backgroundColor is right because it works elsewhere in the script.  I think background is for an image.

I didn't relate all of the code above but I've got a function calling the array elements later on in the script which actually sets the stuff.  That works fine as well.  The script works fine if I put the values directly into the array; it's only when I try to call the colours from the CSS that I run into problems.  It's doesn't matter too much having the colours described in the script but I'd rather keep them in the CSS where they idealy belong.

I don't understand why the parser returns that error either because I have similar code elsewhere in the script that produces no such error.

Maskodok Eko Maskodok Eko
Posts: 171

Jasa SEO Profesional

TOP SEO | Jasa SEO Profesional RajaPoker88.com Agen Texas Poker Dan Domino Online Indonesia Terpercaya IDRPoker.COM Agen Texas Poker dan Domino Online Indonesia Terpercaya POKERSTAR88.com Agen Texas Poker Dan Domino Online Indonesia Terpercaya D

Kokokmas Kokokma Kokokmas Kokokma
Posts: 104

You know, Sim City Societies had a lot of potential, it was a great concept that was horribly developed and lacked any kind of depth. The idea of individualize buildings functioning independently playing its role in a largely diverse and thriving city.

The new Sim City appears to be the classic Sim City gameplay we saw with SC4, combined with a far better developed version of the Societies concepts. Looking great guys, don't let us down.


You must login to reply