SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Apr 2013
    0 Post(s)
    0 Thread(s)

    Bullet-proof Jquery implementation: Capturing click interactions without fail

    Hi, I'm new to this forum and JS coding in general (learner stage!).

    I am using Jquery to fire events when users interact with different elements (primarily click interactions). My concern (due to ignorance probably) is that Jquery can't/wont always work to capture the interaction so my goal is to make minimise that potential failure rate (and learn about when such occurances may happen).

    I've already identified a few complications:

    - element being clicked on has/doesn't have target _blank attribute so delay is necessary
    - people open link in new tab by using Ctrl+Click, right click then "Open in new tab", clicking middle buttons for mouses with custom configuration
    - element is an email address (I've had the code below end up opening the link twice)

    Assuming there are NO JS errors in the code, are there any other situations where the Jquery might not capture the click event? Any browser/device specific situations?

    See my code below for my efforts so far

    HTML Code:
        // Clicked Social Profile
        if ($(this).attr('target').toLowerCase() == '_blank' || e.metaKey || e.ctrlKey || e.which == 2 || e.which == 3) {
          var newtab = true;
        if (!newtab) {
          setTimeout('location.href = "' + this.href  + '"', 150);
    Many thanks for your help!

  2. #2
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    219 Post(s)
    12 Thread(s)
    Hi there,

    Welcome to the forums

    If you bind a click handler to a DOM element, jQuery will always capture that event (providing the element can be clicked on).

    What is it that you are trying to do exactly?

Tags for this Thread


Posting Permissions

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