SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Addict
    Join Date
    Feb 2009
    Location
    Austin Texas
    Posts
    289
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How do I make jQuery click() event accessible?

    I am using jquery's click on a link to trigger an action. I am curious as to how to get it to work with a non-mouse user.

    If the user hits the spacebar or enter key while the link is tab selected, the function is not activated.

    I remember reading about using bind() but I can't find the article.

  2. #2
    SitePoint Zealot
    Join Date
    Apr 2010
    Posts
    112
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    use a hover with a timer lol

  3. #3
    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)
    I just tried this with this very page. I added this JS:

    Code javascript:
    document.getElementById('tabz').onclick = function(e) {
      e.preventDefault();
      alert('a');
    }

    'tabz' is the Home link in the navigation at the top.

    Pressing "enter" when tabz is active produces the alert. I then tried this:

    Code javascript:
    $('#tabz').click(function(e) {
      e.preventDefault();
      alert('b');
    });

    It works pressing enter. You must have made a mistake. Why don't you post your code?

    (spacebar just scrolls down the page BTW)

  4. #4
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ya, they probably should have named it action or activate instead of click.

  5. #5
    SitePoint Addict
    Join Date
    Feb 2009
    Location
    Austin Texas
    Posts
    289
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh it does work with enter. Don't know why I thought it was space. Thanks

  6. #6
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Space works on some form elements.


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
  •