By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,575 Members | 1,377 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,575 IT Pros & Developers. It's quick & easy.

Can I use CSS to specify event handlers ?

P: n/a
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) }
Jul 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
"Richard A. DeVenezia" <ra******@ix.netcom.com> writes:
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 <body onload="init()">
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
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #2

P: n/a

"Richard A. DeVenezia" <ra******@ix.netcom.com> schreef in bericht
news:bj************@ID-168040.news.uni-berlin.de...

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

Jul 20 '05 #3

P: n/a
Janwillem Borleffs wrote:
Is it possible to specify the eventhandler using css ? i.e.
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.

--
David Dorward http://dorward.me.uk/
Jul 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.