Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Changing the content of a stylesheet dynamicly

mac_doggiemac_doggie Member Posts: 488
Hi,

In Firefox the following code works fine, but IE gives a runtime error. Can anyone tell me how to archieve the same in IE. ?

[code]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" />







document.getElementById('aab').innerHTML = "#bbb {background-color:red;}";

bbb



[/code]

I know you will think Why change the style tag contents dynamicly, but I was making a script that loads the css file into a page and make it possible to use variables in css for color and fontnames...

;-)
-mac-
mailto:[email protected]
the Netherlands...

Comments

  • NCS_OneNCS_One Member Posts: 170
    : Hi,
    :
    : In Firefox the following code works fine, but IE gives a runtime error. Can anyone tell me how to archieve the same in IE. ?
    :
    : [code]
    : <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" />
    :
    :
    :
    :
    :
    :
    :
    : document.getElementById('aab').innerHTML = "#bbb {background-color:red;}";
    :
    :
    bbb

    :
    :
    : [/code]
    :
    : I know you will think Why change the style tag contents dynamicly, but I was making a script that loads the css file into a page and make it possible to use variables in css for color and fontnames...
    :
    : ;-)
    : -mac-
    : mailto:[email protected]
    : the Netherlands...
    :
    :

    Hi

    You are getting that error because the Style.InnerHTML is read-only.
  • mac_doggiemac_doggie Member Posts: 488
    : : Hi,
    : :
    : : In Firefox the following code works fine, but IE gives a runtime error. Can anyone tell me how to archieve the same in IE. ?
    : :
    : : [code]
    : : <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" />
    : :
    : :
    : :
    : :
    : :
    : :
    : :
    : : document.getElementById('aab').innerHTML = "#bbb {background-color:red;}";
    : :
    : :
    bbb

    : :
    : :
    : : [/code]
    : :
    : : I know you will think Why change the style tag contents dynamicly, but I was making a script that loads the css file into a page and make it possible to use variables in css for color and fontnames...
    : :
    : : ;-)
    : : -mac-
    : : mailto:[email protected]
    : : the Netherlands...
    : :
    : :
    :
    : Hi
    :
    : You are getting that error because the Style.InnerHTML is read-only.
    :

    That was my conclusion as well. But why... Is there another way to manipulate the styles in a stylesheet, without having to use javascript on each html element like MyDiv.style.backgroundColor = '#e6e6e6';

    I had a perfect script to use variables in CSS, but now I can't use it in IE...

    Please let me know if you have a solution for this...


    ;-)
    -mac-
    mailto:[email protected]
    the Netherlands...


  • NCS_OneNCS_One Member Posts: 170
    : : : Hi,
    : : :
    : : : In Firefox the following code works fine, but IE gives a runtime error. Can anyone tell me how to archieve the same in IE. ?
    : : :
    : : : [code]
    : : : <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" />
    : : :
    : : :
    : : :
    : : :
    : : :
    : : :
    : : :
    : : : document.getElementById('aab').innerHTML = "#bbb {background-color:red;}";
    : : :
    : : :
    bbb

    : : :
    : : :
    : : : [/code]
    : : :
    : : : I know you will think Why change the style tag contents dynamicly, but I was making a script that loads the css file into a page and make it possible to use variables in css for color and fontnames...
    : : :
    : : : ;-)
    : : : -mac-
    : : : mailto:[email protected]
    : : : the Netherlands...
    : : :
    : : :
    : :
    : : Hi
    : :
    : : You are getting that error because the Style.InnerHTML is read-only.
    : :
    :
    : That was my conclusion as well. But why... Is there another way to manipulate the styles in a stylesheet, without having to use javascript on each html element like MyDiv.style.backgroundColor = '#e6e6e6';
    :
    : I had a perfect script to use variables in CSS, but now I can't use it in IE...
    :
    : Please let me know if you have a solution for this...
    :
    :
    : ;-)
    : -mac-
    : mailto:[email protected]
    : the Netherlands...
    :
    :
    :

    Hi

    You can create 2 styles and when you want you change the element class
    or you can use .css files and have a script for writing in the .css file but for this you have to use ActiveX.
  • mac_doggiemac_doggie Member Posts: 488
    : : : : Hi,
    : : : :
    : : : : In Firefox the following code works fine, but IE gives a runtime error. Can anyone tell me how to archieve the same in IE. ?
    : : : :
    : : : : [code]
    : : : : <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" />
    : : : :
    : : : :
    : : : :
    : : : :
    : : : :
    : : : :
    : : : :
    : : : : document.getElementById('aab').innerHTML = "#bbb {background-color:red;}";
    : : : :
    : : : :
    bbb

    : : : :
    : : : :
    : : : : [/code]
    : : : :
    : : : : I know you will think Why change the style tag contents dynamicly, but I was making a script that loads the css file into a page and make it possible to use variables in css for color and fontnames...
    : : : :
    : : : : ;-)
    : : : : -mac-
    : : : : mailto:[email protected]
    : : : : the Netherlands...
    : : : :
    : : : :
    : : :
    : : : Hi
    : : :
    : : : You are getting that error because the Style.InnerHTML is read-only.
    : : :
    : :
    : : That was my conclusion as well. But why... Is there another way to manipulate the styles in a stylesheet, without having to use javascript on each html element like MyDiv.style.backgroundColor = '#e6e6e6';
    : :
    : : I had a perfect script to use variables in CSS, but now I can't use it in IE...
    : :
    : : Please let me know if you have a solution for this...
    : :
    : :
    : : ;-)
    : : -mac-
    : : mailto:[email protected]
    : : the Netherlands...
    : :
    : :
    : :
    :
    : Hi
    :
    : You can create 2 styles and when you want you change the element class
    : or you can use .css files and have a script for writing in the .css file but for this you have to use ActiveX.
    :

    This proofs that IE sucks and Firefox doesn't...
    ;-)
    -mac-
    mailto:[email protected]
    the Netherlands...


  • zibadianzibadian Member Posts: 6,349
    : : : : Hi,
    : : : :
    : : : : In Firefox the following code works fine, but IE gives a runtime error. Can anyone tell me how to archieve the same in IE. ?
    : : : :
    : : : : [code]
    : : : : <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" />
    : : : :
    : : : :
    : : : :
    : : : :
    : : : :
    : : : :
    : : : :
    : : : : document.getElementById('aab').innerHTML = "#bbb {background-color:red;}";
    : : : :
    : : : :
    bbb

    : : : :
    : : : :
    : : : : [/code]
    : : : :
    : : : : I know you will think Why change the style tag contents dynamicly, but I was making a script that loads the css file into a page and make it possible to use variables in css for color and fontnames...
    : : : :
    : : : : ;-)
    : : : : -mac-
    : : : : mailto:[email protected]
    : : : : the Netherlands...
    : : : :
    : : : :
    : : :
    : : : Hi
    : : :
    : : : You are getting that error because the Style.InnerHTML is read-only.
    : : :
    : :
    : : That was my conclusion as well. But why... Is there another way to manipulate the styles in a stylesheet, without having to use javascript on each html element like MyDiv.style.backgroundColor = '#e6e6e6';
    : :
    : : I had a perfect script to use variables in CSS, but now I can't use it in IE...
    : :
    : : Please let me know if you have a solution for this...
    : :
    : :
    : : ;-)
    : : -mac-
    : : mailto:[email protected]
    : : the Netherlands...
    : :
    : :
    : :
    :
    : Hi
    :
    : You can create 2 styles and when you want you change the element class
    : or you can use .css files and have a script for writing in the .css file but for this you have to use ActiveX.
    :
    As an alternative you could also have more than 1 .css file and switch between them using DHTML. This limits your choices in the appearance, but can be done using only javascript.
  • mac_doggiemac_doggie Member Posts: 488
    : : : : : Hi,
    : : : : :
    : : : : : In Firefox the following code works fine, but IE gives a runtime error. Can anyone tell me how to archieve the same in IE. ?
    : : : : :
    : : : : : [code]
    : : : : : <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" />
    : : : : :
    : : : : :
    : : : : :
    : : : : :
    : : : : :
    : : : : :
    : : : : :
    : : : : : document.getElementById('aab').innerHTML = "#bbb {background-color:red;}";
    : : : : :
    : : : : :
    bbb

    : : : : :
    : : : : :
    : : : : : [/code]
    : : : : :
    : : : : : I know you will think Why change the style tag contents dynamicly, but I was making a script that loads the css file into a page and make it possible to use variables in css for color and fontnames...
    : : : : :
    : : : : : ;-)
    : : : : : -mac-
    : : : : : mailto:[email protected]
    : : : : : the Netherlands...
    : : : : :
    : : : : :
    : : : :
    : : : : Hi
    : : : :
    : : : : You are getting that error because the Style.InnerHTML is read-only.
    : : : :
    : : :
    : : : That was my conclusion as well. But why... Is there another way to manipulate the styles in a stylesheet, without having to use javascript on each html element like MyDiv.style.backgroundColor = '#e6e6e6';
    : : :
    : : : I had a perfect script to use variables in CSS, but now I can't use it in IE...
    : : :
    : : : Please let me know if you have a solution for this...
    : : :
    : : :
    : : : ;-)
    : : : -mac-
    : : : mailto:[email protected]
    : : : the Netherlands...
    : : :
    : : :
    : : :
    : :
    : : Hi
    : :
    : : You can create 2 styles and when you want you change the element class
    : : or you can use .css files and have a script for writing in the .css file but for this you have to use ActiveX.
    : :
    : As an alternative you could also have more than 1 .css file and switch between them using DHTML. This limits your choices in the appearance, but can be done using only javascript.
    :

    Why I wanted to do this was because I had made a little JavaScript that subsitutes variables in a stylesheet for their values. I started my stylesheet with a comment that contains the declarations like this:
    [code]
    /*
    $Green1 = #00FF00;
    $Green2 = #00CC66;
    $Red1 = #FF0000;
    $Red2 = #66CC00;
    $Font = Verdana Helvetica Sans-Serif;
    */

    body {
    background-color : $Red1;
    font-family : $Font;
    }

    h1 {
    color : $Green1;
    }

    etc...
    [/code]

    This would be rendered by my JavaScript function to this:

    [code]
    body {
    background-color : #FF0000;
    font-family : Verdana Helvetica Sans-Serif;
    }

    h1 {
    color : #00FF00;
    }

    [/code]

    You get it ?
    I could not accomplish this by just using multiple stylesheets....

    My function worked perfectly in FireFox, but in IE the Style tag is Read-only and so it doesn't work in IE. My question is if you know an alternative way to accomplish the above...


    ;-)
    -mac-
    mailto:[email protected]
    the Netherlands...


Sign In or Register to comment.