[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details

Remove background colour from <li> so hover effect works

Asked by CreativewithTechnology in Cascading Style Sheets (CSS), JavaScript

Tags: css javascript

We have a list item which has a hover effect on each <li>, the hover effect simply changes the background colour.

I've created some javascript to look at what page you are viewing, and change the background colour of the matching <li> so the user can visibly see where they are at in the site.

The problem comes, when the user selected to view another page, the javascript sets the background colour of the next <a> inside the <li> to show they are viewing a new pages, and then removes the background colour on the previous <a> by making the background transparent. This works a treat, however once the background colour of the <a> has been set to transparent, the hover effect on links within that particular <li> no longer work.

Is there a way around this? I've attached snippets of code.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
**** The javascript that sets the background color ****
// Highlight the nav item being viewed
function setNavItem(item) {
    // Set the background color of the selected item
    document.getElementById(item).style.backgroundColor = '#dbf0b0';
    alert(document.getElementById(item).className);
    if (currentNavItem != '') {
        // Clear the previous nav item
        document.getElementById(currentNavItem).style.backgroundColor = 'transparent';
        }
    // Set currentNavItem to the selected item
    currentNavItem = item;
    }
 
**** The List ****
<div id="lhsInner2" class="leftBoxInner"> <img src="images/left-box-inner-img.png" alt="Left image" height="18" width="287" />
            <ul>
              <li><a id="T2_The_Lucky_Few" href="T2_Success_With_MiLife.aspx?page=T2_The_Lucky_Few">the 'lucky' few?</a></li>
              <li><a id="T2_Why_Try_Again" href="T2_Success_With_MiLife.aspx?page=T2_Why_Try_Again">so, why try again?</a></li>
              <li><a id="T2_Personal_Solutions" href="T2_Success_With_MiLife.aspx?page=T2_Personal_Solutions">we need personal solutions...</a></li>
              <li><a id="T2_Personalisation" href="T2_Success_With_MiLife.aspx?page=T2_Personalisation">the difference is personalisation...</a></li>
            </ul>
          </div>
 
**** The CSS ****
.leftBoxInner {
	width: 287px;
	overflow: hidden;
	background: url(../images/left-box-inner-bg.png) bottom repeat-x;
	margin: 0px 0px 0px 1px;
	}
	
.leftBoxInner ul {
	padding: 0px 0px 0px 0px;
	margin: 0px 0px 0px 9px;
	list-style: none;
	}
	
.leftBoxInner ul li {
	color: #93c83a;
	font-size: 75%;
	width: 266px;
	}
	
.leftBoxInner ul li a {
	color: #858484;
	text-decoration: none;
	display: block;
	padding: 3px 0px 3px 20px;
	background: url(../images/left-box-green-bullet.gif) no-repeat left;
	}
 
Related Solutions
Keywords: Remove background colour from <li> …
 
Loading Advertisement...
 
[+][-]08/28/08 05:35 AM, ID: 22334027Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/28/08 07:01 AM, ID: 22334904Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08/28/08 07:37 AM, ID: 22335371Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/28/08 07:40 AM, ID: 22335412Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08/28/08 07:52 AM, ID: 22335552Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/28/08 08:01 AM, ID: 22335694Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08/28/08 06:26 PM, ID: 22341443Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/29/08 12:40 AM, ID: 22343178Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08/29/08 08:17 AM, ID: 22346327Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091118-EE-VQP-93 / EE_QW_2_20070628