Posts

Showing posts with the label javascript

Dynamic Stylesheets using JavaScript

To be more precise in this example, it is practical to have (at least) two style sheets: one for the layout and one for the color of the document. In the following example, we assume that we change the “color” CSS file dynamically. The HTML part There are many ways to apply this technique, but here is the one I choose, that seems very practical to me: to select style sheets dynamically we should declare a style sheet that has an id attribute like the one declared below. In the following example the style sheet declaration has the id “color_css”. It also has a (default) href attribute set to the default color style sheet. <link rel="stylesheet" type="text/css" href="style/colour_1.css" id="color_css" /> We also declare a div section that contains anchors. The div should also have an id attribute; in this case the id is “colours”. Each anchor contains a rel attribute with the value of the (relative) path of the CSS file to be selected. Each t...