473,387 Members | 1,863 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Can I use CSS to specify event handlers ?

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
3 6737
"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

"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: tony kulik | last post by:
This code works fine in ie and opera but not at all in Mozilla. Anybody got a clue as to how to get it right? <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <script...
8
by: Dennis C. Drumm | last post by:
I have a class derived from a SortedList called SystemList that contains a list of objects indexed with a string value. The definition of the objects contained in the SortedList have a boolean...
18
by: bhavin | last post by:
Hi, Can someone point me to some good best practices kind of documentation on use of events compared to method overriding. Ex. In Windows Forms when should i have an event handler for Paint, and...
13
by: Charles Law | last post by:
Mr "yEaH rIgHt" posted the following link about a week ago in answer to my question about removing event handlers. > http://www.vbinfozine.com/t_bindevt.shtml Following on from that post, the...
5
by: Amit | last post by:
Hello! Is it possible to find how many event handlers an event has at runtime? How about finding whether or not an event has event handlers? In C# you can compare the event with null to check if...
7
by: Michael D. Ober | last post by:
Is there anyway to raise an event from a class and require that any program using that class (not just inheritance) have an event handler for specific events in the class? In my case, some events...
6
by: Kevin Attard | last post by:
I am using a GridView inside a UserControl which has a template column for deleting the rows. Before databinding the gridview i am attaching the RowCommand and RowDataBound event. I am using the...
16
by: Hamed | last post by:
Hello I am developing a utility to be reused in other programs. It I have an object of type Control (a TextBox, ComboBox, etc.) that other programmers use it in applications. they may set some...
14
by: Hamed | last post by:
Hello It seems that I should implement ICloneable to implement my own clone object. the critical point for me is to make a control object based on another control object that all of its event...
6
by: Tony Johansson | last post by:
Hello! I know it's possible to have several event handler for a single event but I can't see any point using several event handler for this. I'm probably wrong so can anybody tell me what...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.