Can I Use Javascript to do this?

Discussion in 'JavaScript' started by lock, Apr 13, 2008.

  1. #1
    I am wanting to set up a site that has different stylesheets attached, when someone clicks a link, a different stylesheet is loaded. Can this be done in JacaScript, if so how would I go about it?

    Also is Javascript the best method for this?
     
    lock, Apr 13, 2008 IP
  2. lock

    lock Banned

    Messages:
    205
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Anyone? Is Javascript dead?
     
    lock, Apr 15, 2008 IP
  3. eTechDude.com

    eTechDude.com Member

    Messages:
    205
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    28
    #3
    var oLink = document.createElement("link")
    oLink.href = "mypath/mycss.css";
    oLink.rel = "stylesheet";
    oLink.type = "text/css";
    document.body.appendChild(oLink);
    Code (markup):
    OR

    if (document.layers) {
    document.write('<link rel=stylesheet href="nn4.css">')
    }
    else {
    document.write('<link rel=stylesheet href="main.css">')
    }
    Code (markup):
     
    eTechDude.com, Apr 16, 2008 IP
  4. lock

    lock Banned

    Messages:
    205
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Would this be set in the head or at each link?
     
    lock, Apr 16, 2008 IP