473,406 Members | 2,745 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Change/Add CSS class to parent element on mouseover?

8
I have a <div id="nav-left"> and I want a mouseover command that would add a class to that div, like this <div id="nav-left" class="magic">. It would work similar to this example:

Expand|Select|Wrap|Line Numbers
  1. <p onmouseover="this.style.color='red'" onmouseout="this.style.color='black'">Move the mouse pointer over this text to change its color. Move the pointer off the text to change the color back.</p>
Where that code refers to "this" I need to refer to the div element (see my actual HTML below). Also, that code adds an inline style and I would rather add a class, but I could live with adding an inline style for the background image position. I am trying to make the background image sprite for the div reposition when mousing over the links. Of course I want it to go back to normal on mouseout.

Expand|Select|Wrap|Line Numbers
  1. <div id="nav-left">
  2.     <ul>
  3.         <li><a id="btn-elves" href="#" title="Magic">Magic Elves</a></li>
  4.         <li><a id="btn-new" href="#" title="New">New</a></li>
  5.         <li><a id="btn-accessories" href="#" title="Accessories">Accessories</a></li>
  6.     </ul>
  7. </div>
Jul 28 '10 #1

✓ answered by JKing

Expand|Select|Wrap|Line Numbers
  1.     <div id="nav-left">
  2.         <ul>
  3.             <li><a id="btn-elves" href="#" title="Magic" onmouseover="getElementById('nav-left').className='magic'" onmouseout="getElementById('nav-left').className='notmagic'">Magic Elves</a></li>
  4.             <li><a id="btn-new" href="#" title="New">New</a></li>
  5.             <li><a id="btn-accessories" href="#" title="Accessories">Accessories</a></li>
  6.         </ul>
  7.     </div> 

2 5487
JKing
1,206 Expert 1GB
Expand|Select|Wrap|Line Numbers
  1.     <div id="nav-left">
  2.         <ul>
  3.             <li><a id="btn-elves" href="#" title="Magic" onmouseover="getElementById('nav-left').className='magic'" onmouseout="getElementById('nav-left').className='notmagic'">Magic Elves</a></li>
  4.             <li><a id="btn-new" href="#" title="New">New</a></li>
  5.             <li><a id="btn-accessories" href="#" title="Accessories">Accessories</a></li>
  6.         </ul>
  7.     </div> 
Jul 28 '10 #2
draney
8
@JKing
Thanks!! It is perfect.
Jul 28 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Paul Gobée | last post by:
What is the parent element of a button (IE6 on Win, transitional mode)? Is it the BODY, the browser default stylesheet, or something else? Contra "body is parent-element": - Buttons with no...
3
by: Markus Ernst | last post by:
Hello Reading the follwing document: http://www.w3.org/TR/WD-positioning-970131#In-flow it seems very clear that position:relative should be relative to the parent element. So in the following...
4
by: Grey Plastic | last post by:
I have several classes that all keep track of static data. However, the manner that they keep track of static data is identical, and so I'm using the template<class Child> class Parent { ... };...
1
by: MSNews | last post by:
I am new to ASP.NET and have found these context errors in the HTML for the ASPX pages, the site/pages work fine. Can anyone explain why these warning are coming up? Regards
2
by: Paul Darroch | last post by:
Hello I am trying to convert a web site from ASP to ASP.NET and the class attribute is used in tables throughout the site. The problem is when I am trying to convert these pages I have a huge...
4
by: patrizio.trinchini | last post by:
Hi all, I'm new to XSLT and maybe my problem have a very trivial answer, but I need an expert that point me in the right direction. What I would obtain is to remove all the elements that have a...
0
by: sandycormie | last post by:
Hello I suspect the answer is going to be no, but... I have a class that contains a property defined as an abstract class. I would like to control the format of the generated XML to include a...
2
by: dd | last post by:
I need to know whether an element can move itself to a new parent within the DOM. I can't find any function that offers me such an ability. Here's an example of a hierarchy: -body ....div 1 ...
22
by: waltapp | last post by:
Hello, I am working in javascript and I need to access the parent element. I have 4 different html documents in the same folder. The names are title, code, golf,tree. I am currently in the title...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.