Solved

getElementsByTagName("li") change colour text and background

Posted on 2004-08-11
2
540 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
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…

708 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now