Javascript conditional statment

Discussion in 'JavaScript' started by dean5000v, Mar 2, 2009.

  1. #1
    ok well ive used this javascript to select images and load them as a div tag background.

    <a href="javascript:changeImage(0);" class="border_black"><img src="images/card_example1_thumb.gif" style="border: 1px solid black;" alt="" /></a>
    <a href="javascript:changeImage(1);" class="border_black"><img src="images/card_example2_thumb.gif" style="border: 1px solid black;" alt="" /></a>

    is there a way i could do a conditional statement in JavaScript that will load a particular style sheet for each one depending which one was selected.

    for example load style sheet 1 if the first one is selected ?
     
    dean5000v, Mar 2, 2009 IP
  2. dimitar christoff

    dimitar christoff Active Member

    Messages:
    882
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    90
    #2
    sure. basically, this is to do with bringing in assets into the page dynamically.

    define a <link href="nohref" rel="stylesheet" type="text/css" id="condCSS" />

    under changeImage, you can just apply:
    
    var csstoLoad = (num == 0) ? "/newCSS-1.css" : "/css2.css";
    document.getElementById("condCSS").setAttribute("href", csstoLoad);
    PHP:
    i have not tested any of the above but i don't see a problem with it. under mootools i'd simply do:
    new Asset.css(csstoLoad);
    PHP:
    http://mootools.net/docs/Plugins/Assets#Assets:css
     
    dimitar christoff, Mar 2, 2009 IP
  3. siothach

    siothach Active Member

    Messages:
    656
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    60
    #3
    siothach, Mar 3, 2009 IP