Can I use CSS to specify event handlers ?

  • Thread starter Richard A. DeVenezia
  • Start date
R

Richard A. DeVenezia

Can I use CSS to set onmouseover ?

In HTML I have a bunch of <A HREF="whatever"
onmouseover=eventhandler(this)">stuff</A>. I would prefer not to have the
onmouseover 'pollution'

Is it possible to specify the eventhandler using css ? i.e.

<A HREF="whatever" class="foo">stuff</A>.

A.foo { on-mouse-over: eventhandler(this) }
 
L

Lasse Reichstein Nielsen

Richard A. DeVenezia said:
Can I use CSS to set onmouseover ?

No.

CSS is all about presentation. It is about how things look, not how
they act.
In HTML I have a bunch of <A HREF="whatever"
onmouseover=eventhandler(this)">stuff</A>. I would prefer not to have the
onmouseover 'pollution'

You can assign them with Javascript instead.

document.links['aId'].onmouseover = eventhandler;

Make a lot of these in a function that is run when the page is loaded,
and you can get away with only said:
Is it possible to specify the eventhandler using css ? i.e.

<A HREF="whatever" class="foo">stuff</A>.

A.foo { on-mouse-over: eventhandler(this) }

So, no.

<hack>
There is one ugly thing you can do: make URLs with the Javascript:
pseudo protocol in CSS.

Try adding:
a.foo:hover { background: url("javascript:alert('Gotcha')"); }
and see what happens when you move over the a element :)

Works in IE and Opera, not in Mozilla.

In practice: Don't. This is purely for fun.
</hack>

/L
 
J

Janwillem Borleffs

Richard A. DeVenezia said:
Is it possible to specify the eventhandler using css ? i.e.

<A HREF="whatever" class="foo">stuff</A>.

A.foo { on-mouse-over: eventhandler(this) }

This is limited to a.foo:hover, which acts like an onmouseover handler. In
IE, you can also combine it with the expression keyword:

a.foo:hover { cssProperty:expression(myfunc()) }

Where cssProperty is a valid css property like color, font-size, width,
height etc. and myfunc() a user defined function that returns the property's
value.


JW
 
D

David Dorward

This is limited to a.foo:hover, which acts like an onmouseover handler. In
IE, you can also combine it with the expression keyword:

.... which isn't CSS.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top