Solved

getElementsByTagName("li") change colour text and background

Posted on 2004-08-11
2
543 Views
Last Modified: 2008-03-06
Hi Experts

I am trying to change colour on a menu under <UL> <LI> as the mouse moves over and back to normal when it moves out, I can get it working when it moves over but no luck when it moves out, could you please help, PS i dont want to use ID's and I don't want to place it in a table...that just makes it too easy lol...Cheers

Here is my function

function li(ElementNumber,backcolor,textcolor)

       {

         document.getElementsByTagName("li")[ElementNumber].style.backgroundColor = backcolor;
         document.getElementsByTagName("li")[ElementNumber].style.color = textcolor;
         
       }

<DIV id="ul">
<ul>
  <li onmouseover="li(0,'white','gray')";onmouseout="li(0,'gray','white')">Armani</li>
  <li onmouseover="li(1,'white','gray')";onmouseout="li(1,'gray','white')">Oakley</li>
  <li onmouseover="li(2,'white','gray')";onmouseout="li(2,'gray','white')">Versace</li>
</ul>
</div>
0
Comment
Question by:baz_can_fix_it
2 Comments
 
LVL 36

Accepted Solution

by:
Zyloch earned 50 total points
ID: 11780079
Hi

Have it like this:

  <li onmouseover="li(0,'white','gray');" onmouseout="li(0,'gray','white')">Armani</li>
  <li onmouseover="li(1,'white','gray');" onmouseout="li(1,'gray','white')">Oakley</li>
  <li onmouseover="li(2,'white','gray');" onmouseout="li(2,'gray','white')">Versace</li>

Regards,
Zyloch
0
 
LVL 1

Author Comment

by:baz_can_fix_it
ID: 11780120
Too easy...silly me...Thanx heaps mate

Cheers
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question