problem using javascript to apply a color to an <li>

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jonbridgman
    New Member
    • Mar 2011
    • 7

    #1

    problem using javascript to apply a color to an <li>

    In the code below I can sucessfully target an <li> and change it's font size and font weight, but not color.

    Am I missing something?

    Javascript
    Code:
     
    
    //MOUSEOVER 
    function ChangeText(block, blockItem) {
    	if(block==0 && objCounter!=blockItem){	
    		document.getElementById("objectiveList").children[blockItem].className ="links_rolled"; 
    	}
    }
    //MOUSEOFF 
    function ChangeBack(block, blockItem) {
    	if(block==0 && objCounter!=blockItem){
    			document.getElementById("objectiveList").children[blockItem].className = "links_normal";  
    	}	
    
    }
    CSS

    Code:
    .links_rolled{
    color: #33FF66;
    font-size:36px
    }
    
    .links_normal{
    color: 	#000000;
    font-size:10px
    }

    As a newbie to using forums like this to ask questions, should I provide a link to the page? thanks for any help.
    Last edited by jonbridgman; Mar 16 '11, 08:11 PM. Reason: fixed code tags
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    These are links? Link text color is defined by the following attributes.

    Code:
    a:link {color:#FF0000;}      /* unvisited link */
    a:visited {color:#00FF00;}  /* visited link */
    a:hover {color:#FF00FF;}  /* mouse over link */
    a:active {color:#0000FF;}  /* selected link */

    Comment

    • dgreenhouse
      Recognized Expert Contributor
      • May 2008
      • 250

      #3
      As Rabbit alludes to, using CSS psuedo-classes is the most efficient method.
      Plus, if JavaScript is disabled you still get the dynamic styling changes you're after.

      See:
      A CSS pseudo-class is a keyword added to a selector that lets you select elements based on information that lies outside of the document tree, such as a specific state of the selected element(s). For example, the pseudo-class :hover can be used to style a button when a user's pointer hovers over it.

      The MDN Web Docs site provides information about Open Web technologies including HTML, CSS, and APIs for both Web sites and progressive web apps.

      Comment

      • jonbridgman
        New Member
        • Mar 2011
        • 7

        #4
        thanks for your reply. That's so obviously a better way to do this it's shocking. thanks!

        Comment

        Working...