Posted by Toby Inkster on 04/29/06 17:40
Mice Over wrote:
> But my main question was this: the statements that use phrases like
> "onmouseover" and "onmouseout" can be used in as style attributes
onmouseover / onmouseout are HTML attributes that fire event handling
code, usually written in Javascript -- they have nothing to do with CSS as
such.
What I think you're trying to ask is: "is there a way of assigning
code to happen in response to events without littering my code with lots
of onmouseover attributes?"
The answer is yes, but it doesn't involve CSS. Here's a quick example:
<script type="text/javascript">
// Utility function -- this is often useful!
function addLoadEvent (func)
{
var oldonload = window.onload;
if (typeof window.onload != 'function')
{
window.onload = func;
}
else
{
window.onload = function()
{
oldonload();
func();
}
}
}
function myfunc1 ()
{
window.alert("Hello");
}
function init_behaviours ()
{
var els = document.getElementsByTagName("TD");
for (var i=0; els[i]; i++)
els[i].onmouseover = myfunc1;
}
addLoadEvent(init_behaviours);
</script>
This will attach the behaviour "myfunc1" to all table cells onmouseover
events.
--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact
Now Playing ~ ./b52s_-_love_shack.ogg
Navigation:
[Reply to this message]
|