SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot
    Join Date
    Dec 2006
    Posts
    135
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    can mouse trigger js without an anchor tag?

    I have a div that contains a few anchor tags. I would like to trigger a particular javascript function whenever the mouse enters the div area.

    Can such a trigger happen without an anchor tag? Obviously I can't surround anchors with another anchor so I'm at a bit of a loss as to how else I can trigger the function via a mouse action.

    Any suggestions are appreciated.

  2. #2
    SitePoint Wizard
    Join Date
    Dec 2003
    Location
    USA
    Posts
    2,582
    Mentioned
    29 Post(s)
    Tagged
    0 Thread(s)
    Nearly all elements implement the event attributes (onclick, onmouseover, etc.), so you can just attach it to the div itself.

  3. #3
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,718
    Mentioned
    103 Post(s)
    Tagged
    4 Thread(s)
    Be careful though, because every element inside the div will trigger an event that bubbles up to the event on the div element.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  4. #4
    SitePoint Zealot
    Join Date
    Dec 2006
    Posts
    135
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks. Yes, that does work and so simple. Do you know how well it works with all browsers? I don't have access to anything but ie7 and ff2 at the moment.

  5. #5
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,718
    Mentioned
    103 Post(s)
    Tagged
    4 Thread(s)
    Version 4 browsers were troublesome. Netscape supported event capturing whereas Microsoft used event bubbling.

    After that both were supported.
    For more details see http://www.quirksmode.org/js/events_order.html
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •