how to replace "href" attributes in <link>

Discussion in 'Programming' started by linjuming, Jun 27, 2009.

  1. #1
    
    <head>
    <link href="{dede:cmsurl}/default/blueidea1.css" type="text/css" rel="stylesheet"/>
    <link href="{dede:cmsurl}/default/blueidea2.css" type="text/css" rel="stylesheet"/>
    <link href="{dede:cmsurl}/default/blueidea3.css" type="text/css" rel="stylesheet"/>
    </head>
    
    HTML:
    I want to replace the href attributes in the <link> tag , can anyone help write a js snippet for me? I am a newbie of js.
    the result should be below:

    
    <head>
    <link href="{dede:cmsurl}/test/blueidea1.css" type="text/css" rel="stylesheet"/>
    <link href="{dede:cmsurl}/test/blueidea2.css" type="text/css" rel="stylesheet"/>
    <link href="{dede:cmsurl}/test/blueidea3.css" type="text/css" rel="stylesheet"/>
    </head>
    
    HTML:
    My english is poor , I can only write chinese English , I am sorry for anyone who can not understand what the problem I am asking.
     
    linjuming, Jun 27, 2009 IP
  2. FDIM

    FDIM Member

    Messages:
    55
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    43
    #2
    Add id for "link" tag for example:
    
    <link id="link1" href="{dede:cmsurl}/default/blueidea3.css" type="text/css" rel="stylesheet"/>
    
    Code (markup):
    then use this js code:
    
    document.getElementById('link1').href='www.example.com/style.css';
    
    Code (markup):
     
    FDIM, Jun 28, 2009 IP