Calling onmouseover by ID or tag

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
GeXus
Forum Regular
Posts: 631
Joined: Sat Mar 11, 2006 8:59 am

Calling onmouseover by ID or tag

Post by GeXus »

Does anyone know of a good tutorial or have an example of how to assign onmouseover events to IDs or Tags, without having the onmouseover code within each and every tag.

Thanks!
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

If memory serves:

Code: Select all

var o = document.getElementById('foo');
if (o)
{
  o.onmouseover = function(){alert('yay!');}
}
GeXus
Forum Regular
Posts: 631
Joined: Sat Mar 11, 2006 8:59 am

Post by GeXus »

Nice, Thanks!
GeXus
Forum Regular
Posts: 631
Joined: Sat Mar 11, 2006 8:59 am

Post by GeXus »

Do you know how you could apply this only to an element that is within another? Here is the situation, I have several list elements on my page, but I only want this even to effect one specific list.. which is contained within a div that has an ID.. and the elements that will have the moseover are li's.


Thanks!
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

XPath may be of interest, but not all the browsers support it just yet.

You can traverse the children of the object using the DOM.
Post Reply