Can I use CSS to specify event handlers ?

Discussion in 'Javascript' started by Richard A. DeVenezia, Sep 1, 2003.

  1. 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) }
    Richard A. DeVenezia, Sep 1, 2003
    #1
    1. Advertising

  2. "Richard A. DeVenezia" <> 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 -
    Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
    'Faith without judgement merely degrades the spirit divine.'
    Lasse Reichstein Nielsen, Sep 1, 2003
    #2
    1. Advertising

  3. "Richard A. DeVenezia" <> schreef in bericht
    news:bj009o$dr5j2$-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
    Janwillem Borleffs, Sep 1, 2003
    #3
  4. 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/
    David Dorward, Sep 1, 2003
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Inertia_sublimation
    Replies:
    2
    Views:
    414
    Babu Kalakrishnan
    Oct 13, 2004
  2. TS
    Replies:
    12
    Views:
    1,306
  3. Gert Unterhofer
    Replies:
    0
    Views:
    137
    Gert Unterhofer
    Jul 17, 2006
  4. Fred
    Replies:
    1
    Views:
    118
    Lasse Reichstein Nielsen
    Jul 18, 2003
  5. Replies:
    1
    Views:
    131
    Dietmar Meier
    Apr 15, 2005
Loading...

Share This Page