SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict ArunB's Avatar
    Join Date
    Jun 2008
    Location
    Hyderabad
    Posts
    252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question onClick cause firing onFocus

    For a div element, both onClick and onFocus events are binded. When I am clicking on that element, onFocus event is also firing. How can I stop firing of onFocus event when I click on that element?

  2. #2
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    onfocus does not work on divs.

  3. #3
    SitePoint Addict ArunB's Avatar
    Join Date
    Jun 2008
    Location
    Hyderabad
    Posts
    252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry, it is a Hyper Link.

  4. #4
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    onfocus will fire when you focus it. onclick when you click on it.

    What do you want to do differently?

  5. #5
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    The thing is that clicking a link automatically also focuses and you can't do anything about that except blur() it immediately afterwards. However, if you're trying to keep something else in focus at the same time as clicking the link, that's more difficult and would require keeping the currently focused element in a holding area elsewhere.

    In brief: You can't have focus on more than one thing at once. You can do this:
    Code JavaScript:
    something.onclick = function() {
      this.blur(); // remove focus from the clicked link
      // other code
    }
    It's practically immediate.


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
  •