Help finding an error

Discussion in 'HTML & Website Design' started by pinkytoe, Dec 11, 2012.

  1. #1
    Hey guys

    I am trying to add an element to a webpage that allows the user to choose a different style sheet when on the page.

    I am not really able to see what I am missing here.

    Here is the codes:

    Page HTML

    <head>
    
    <title>Page Title</title>
    	<link href="contact_us.css" rel="stylesheet" type="text/css" title="default" />
    	<link href="alternative_sheet.css" rel="alternative stylesheet" type="text/css" title="other" />
    	
    </head>
    
    <body>
    
    	
    			
    		<p>	
    			<a href="#" id="Default">Default Styles</a>
                            <a href="#" id="Other">Other Styles</a>
    
    		</p>
    		
    	
    	
    </body>
    
    
    </html>
    Code (markup):

    JavaScript:

    /* Reference: http://www.alistapart.com/articles/alternate/
       Retrieved: December 18th, 2010 */
       
    var defaultStyleLink, otherStyleLink;
    
    defaultStyleLink = document.getElementById("Default");
    otherStyleLink = document.getElementById("Other");
    
    function setActiveStyleSheet ( styleId ) {
    
    	var i = 0;
    	var linkItem, linkArray;
    	
    	linkArray = document.getElementsByTagName( "link" );
    	
    	for ( i = 0; i < linkArray.length; i++ ) {
    		
    		linkItem = linkArray[i];
    			
    		if ( linkItem.getAttribute( "rel" ).indexOf( "style" ) != -1 && linkItem.getAttribute( "title" ) ) {
    			linkItem.disabled = true;
    				
    			if ( linkItem.getAttribute( "title" ) === styleId ) {
    				linkItem.disabled = false;
    			}
    		}
    	}
    }
    
    defaultStyleLink.onclick = function() {
    	setActiveStyleSheet( this.id );
    };
    
    otherStyleLink.onclick = function() {
    	setActiveStyleSheet( this.id );
    };
    
    	
    Code (markup):

    Can anyone see any errors here?


    Thanks
     
    pinkytoe, Dec 11, 2012 IP
  2. pinkytoe

    pinkytoe Member

    Messages:
    47
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #2
    Anyone have any ideas?
     
    pinkytoe, Dec 12, 2012 IP