Can I use CSS to specify event handlers ?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Richard A. DeVenezia

    #1

    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=eve nthandler(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">stu ff</A>.

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


  • Lasse Reichstein Nielsen

    #2
    Re: Can I use CSS to specify event handlers ?

    "Richard A. DeVenezia" <radevenz@ix.ne tcom.com> writes:
    [color=blue]
    > Can I use CSS to set onmouseover ?[/color]

    No.

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

    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()" >
    [color=blue]
    > Is it possible to specify the eventhandler using css ? i.e.
    >
    > <A HREF="whatever" class="foo">stu ff</A>.
    >
    > A.foo { on-mouse-over: eventhandler(th is) }[/color]

    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 - lrn@hotpop.com
    Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
    'Faith without judgement merely degrades the spirit divine.'

    Comment

    • Janwillem Borleffs

      #3
      Re: Can I use CSS to specify event handlers ?


      "Richard A. DeVenezia" <radevenz@ix.ne tcom.com> schreef in bericht
      news:bj009o$dr5 j2$1@ID-168040.news.uni-berlin.de...[color=blue]
      >
      > Is it possible to specify the eventhandler using css ? i.e.
      >
      > <A HREF="whatever" class="foo">stu ff</A>.
      >
      > A.foo { on-mouse-over: eventhandler(th is) }
      >
      >[/color]

      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:exp ression(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



      Comment

      • David Dorward

        #4
        Re: Can I use CSS to specify event handlers ?

        Janwillem Borleffs wrote:
        [color=blue][color=green]
        >> Is it possible to specify the eventhandler using css ? i.e.[/color][/color]
        [color=blue]
        > This is limited to a.foo:hover, which acts like an onmouseover handler. In
        > IE, you can also combine it with the expression keyword:[/color]

        .... which isn't CSS.

        --
        David Dorward http://dorward.me.uk/

        Comment

        Working...