View Full Version : grab style attribute

12-15-2004, 07:41 PM
Background: I am making a script that makes a table have a static header by just adding the script to the page and calling it with the table name.

I am using this code to apply the attributes of the orginal table to the new header table:

//Apply CSS to the static table
theOrgTable = document.getElementById(xDataGridName);
theNewTable = document.getElementById("theAddon_" + xDataGridName);
if(theOrgTable.attributes[x].nodeValue && theOrgTable.attributes[i].nodeName.toLowerCase() != "id"){

Now that works all fine and dandy except for when the person (or asp.net generated code) uses the style attribute in the table tag instead of a class.

The value that the script above says for the style attribute is 'null'

I tried to loop through the css rules for the style attribute like you should for a style sheet, but that did not work. I tried to apply the style object directly to the other style and that did not work.

Anyone have any clue on how I can access the elements inside of that style attributes object?


Willy Duitt
12-15-2004, 08:22 PM
Have you tried getComputedStyle() ??

12-15-2004, 09:04 PM
I used that along with IE equiv currentStyle.

I was not able to figure out how to access the elements of it without knowing all of the items inside the style tag.

For instance I have no clue if there is a background-color, font, color, etc. in the tag since it is generated by another process I have no control over.

I really do not want to put 25+ statements to grab the possibilities.


12-15-2004, 09:07 PM

12-15-2004, 09:41 PM
Is it possible to set one elements style equal another elements currentStyle/getComputedStyle?


12-15-2004, 10:14 PM
Okay I can get it to work in Mozilla and not IE. What a surprise!

function makeSame(elem_1, elem_2){

//IE (no-clue)
if (elem_1.currentStyle){
//output parameters to see if there is a style
for (prop in elem_1.currentStyle){
tStr += prop + " : " + elem_1.currentStyle[prop] + "<br>";
//Mozilla (works)
else if (window.getComputedStyle){
elem_1x=window.getComputedStyle(elem_1, "");
elem_2x=window.getComputedStyle(elem_2, "");
elem_2x = elem_1x;

The IE code just loops through the properties in the currentStyle object. I tried to do it the same way with Mozilla but it gives an error!

Time to go home for the day!

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum