Advertisement

08.28.2008 at 02:42AM PDT, ID: 23684830 | Points: 500
[x]
Attachment Details

Remove background colour from <li> so hover effect works

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

Tags:

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.Start Free Trial
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;
	}
[+][-]08.28.2008 at 05:35AM PDT, ID: 22334027

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.2008 at 07:01AM PDT, ID: 22334904

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.2008 at 07:37AM PDT, ID: 22335371

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.2008 at 07:40AM PDT, ID: 22335412

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.2008 at 07:52AM PDT, ID: 22335552

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.2008 at 08:01AM PDT, ID: 22335694

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.2008 at 06:26PM PDT, ID: 22341443

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.2008 at 12:40AM PDT, ID: 22343178

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.2008 at 08:17AM PDT, ID: 22346327

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...
20081112-EE-VQP-44 / EE_QW_2_20070628