Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

getElementsByTagName("li") change colour text and background

Posted on 2004-08-11
2
Medium Priority
?
548 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 200 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
This article discusses how to implement server side field validation and display customized error messages to the client.
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…
Suggested Courses

927 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