www.webdeveloper.com
Results 1 to 3 of 3

Thread: Onclick : hightlightLink function doesn't work ?

  1. #1
    Join Date
    Nov 2012
    Posts
    4

    Onclick : hightlightLink function doesn't work ?

    My HTML

    HTML Code:
    <ul id="nav">
    <li><a href="#">Link 1</a></li>
    <li><a href="#">Link 2</a></li>
    <li><a href="#">Link 3</a></li>
    </ul>
    My CSS

    Code:
    #nav {
    	list-style-type: none;
    	margin: 0;
    	padding: 0;
    	width: 800px;
    	height: 35px;
    }
    
    #nav li {
    	float: left;
    }
    
    #nav li a {
    	display: block;
    	line-height: 35px;
    	width: 200px;
    	background-color: #C0C0C0;
    	text-decoration: none;
    	text-align: center;
    }
    My JS

    Code:
    function highlightLink() {
    	var nav = document.getElementById("nav");
    	var links = nav.getElementsByTagName("a");
    	for(var i=0;i<links.length;i++) {
    		links[i].style.backgroundColor = "blue";
    		links[i].onclick = function() {
    			links[i].style.backgroundColor = "red";
    		}
    	}
    }
    
    showArticleBar();
    Last edited by thisisabanana; 07-07-2013 at 04:47 AM.

  2. #2
    Join Date
    Jul 2011
    Posts
    131
    What does function showArticleBar() do?
    And where do you call highlightLink function?

  3. #3
    Join Date
    Jul 2013
    Posts
    11
    and what would you like to do?

    wouldn't be

    #nav li a:hover{...}
    " " ":active
    " " ":visited

    be enought?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles