Page 1 of 1
Calling onmouseover by ID or tag
Posted: Mon Feb 05, 2007 9:12 am
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!
Posted: Mon Feb 05, 2007 9:19 am
by feyd
If memory serves:
Code: Select all
var o = document.getElementById('foo');
if (o)
{
o.onmouseover = function(){alert('yay!');}
}
Posted: Mon Feb 05, 2007 9:43 am
by GeXus
Nice, Thanks!
Posted: Mon Feb 05, 2007 11:19 am
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!
Posted: Mon Feb 05, 2007 11:30 am
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.