Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts

    grab style attribute

    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:

    Code:
    //Apply CSS to the static table
    theOrgTable = document.getElementById(xDataGridName);
    theNewTable = document.getElementById("theAddon_" + xDataGridName);
    for(i=0;i<theOrgTable.attributes.length;i++){
      if(theOrgTable.attributes[x].nodeValue && theOrgTable.attributes[i].nodeName.toLowerCase() != "id"){
        theNewTable.setAttribute(theOrgTable.attributes[i].nodeName,theOrgTable.attributes[i].nodeValue);
      }
    }
    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?

    Thanks,
    Eric

  • #2
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Have you tried getComputedStyle() ??

  • #3
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    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.

    Eric

  • #4
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    MISTAKE.....
    Last edited by A1ien51; 12-15-2004 at 09:33 PM.

  • #5
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    Is it possible to set one elements style equal another elements currentStyle/getComputedStyle?

    Eric

  • #6
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    Okay I can get it to work in Mozilla and not IE. What a surprise!

    Code:
    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>";
        }
        document.write(tStr);
      }
      //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!
    Eric


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •