This problem might be caused by two things

1. The DOM is not ready yet when you attached the listener

2. Your HTML code is added dynamically

The solution for the first case is to put your code under the ready block

$(document).ready(function(){
    $('.pinterest-button').click(function() {
        $('.pinterest-button').hide();
        $('#pin1 a img').click();
        setTimeout("$('.pinterest-button').show();", 1000);
    });
}); 

The solution for the 2nd case is to make the listener live for any changes

 $(document).ready(function(){
        $('.pinterest-button').on('click',function() {
            $('.pinterest-button').hide();
            $('#pin1 a img').click();
            setTimeout("$('.pinterest-button').show();", 1000);
        });
    }); 

and add the on click to your image listener if needed

I hope this can help

Answer from Seder on Stack Overflow
🌐
Apple Community
discussions.apple.com › thread › 255081474
Command-click not opening new tab in Safari
Safari Links will not open I’m having trouble opening links within safari, I have to hold my finger over the link and select open in new browser. Before when selecting the link it would just open. 1125 2 ... Right-click > Open Link in new tab usually work in such pages where cmd-click fails.
Discussions

keyboard - Command + Click not opening links in new tabs - Ask Different
Do you updated Chrome recently? Which extensions do you have installed? Does Cmd + Click work in Safari and Firefox? ... Command works just fine with hotkeys like Command + O to open files. Command + Click is not working in Firefox or Safari either. Yes, I tried that extension, it didn't help. More on apple.stackexchange.com
🌐 apple.stackexchange.com
Command + tap-to-click not working proper… - Apple Community
I've tested this in both Safari and Chrome to make sure it's not a browser issue. Both behave the same. It appears that tap-to-click is not coming through as long as you haven't moved the pointer since you pressed down the cmd key. The reason the second or third click usually does work, is because ... More on discussions.apple.com
🌐 discussions.apple.com
November 19, 2021
macos - Some click dont work in Safari browser using selenium standalone server - Stack Overflow
Hi I am using Selenium Standalone Server along with Selenese command executor for testing on Safari on Mac OS X. Im facing issues in clicking some buttons on specific pages. The same clicks work More on stackoverflow.com
🌐 stackoverflow.com
SafariDriver click on a button not working with safari 13.0.1
I am using Selenium 3.141 with SafariDriver included with Safari 13.0.1 (14608.2.11.1.11). I have problems with interacting with elements, in this case clinking on a button. ... RESULT: The click is not performed on the button element but any element below the button element. This is not working ... More on developer.apple.com
🌐 developer.apple.com
June 22, 2023
🌐
Apple Community
discussions.apple.com › thread › 253382140
Command + tap-to-click not working proper… - Apple Community
November 19, 2021 - I've tested this in both Safari and Chrome to make sure it's not a browser issue. Both behave the same. It appears that tap-to-click is not coming through as long as you haven't moved the pointer since you pressed down the cmd key. The reason the second or third click usually does work, is because by then you have changed the mouse position ever so slightly by touching the pad to click.
🌐
Dartmouth College
services.dartmouth.edu › TDClient › 1806 › Portal › KB › ArticleDet
Safari is not Responding to Mouse Clicks - ser - Dartmouth
Shut down your computer. Restart while holding the Command and R keys to start in Recovery Mode. Note that you only need to hold down both keys until you see the Apple logo displayed.
🌐
Apple Developer
developer.apple.com › forums › thread › 123685
SafariDriver click on a button not working with safari 13.0.1
June 22, 2023 - I am using Selenium 3.141 with SafariDriver included with Safari 13.0.1 (14608.2.11.1.11). I have problems with interacting with elements, in this case clinking on a button. ... RESULT: The click is not performed on the button element but any element below the button element. This is not working from the recent update to safari 13.0.1.
Find elsewhere
🌐
MacRumors
forums.macrumors.com › macs › macos › older macos versions › macos monterey (12)
Weird bug on Safari/browsers driving me nuts. Cmd+Tap (tap to click) does not open link in new tab. | MacRumors Forums
November 4, 2021 - With 'Tap to click' function enabled on the Trackpad settings, holding Cmd+Tap (not a deep press) on a link in Safari or any other browser (I first discovered in Brave browser) to open link in a new tab will not work and be unresponsive around 50% of the time on the first interaction.
Top answer
1 of 2
4

The issue is completely solved. The point is element of input[type=file] must not be display: none. Look at sample below:

function click(el) {
  // Simulate click on the element.
  var evt = document.createEvent('Event');
  evt.initEvent('click', true, true);
  el.dispatchEvent(evt);
}

document.querySelector('#selectFile').addEventListener('click', function(e) {
  var fileInput = document.querySelector('#inputFile');
  //click(fileInput); // Simulate the click with a custom event.
  fileInput.click(); // Or, use the native click() of the file input.
}, false);
<input id="inputFile" type="file" name="file" style="visibility:hidden; width:0; height:0">
<button id="selectFile">Select</button>

2 of 2
1

Trigger the click event on the DOM element rather than the jQuery object. That should work in all browsers.

 $('#ajxAttachFiles')[0].click();

Or:

document.getElementById('ajxAttachFiles').dispatchEvent( new Event('click') );
//for IE < 9 use microsoft's document.createEventObject 

var elem=$('<input id="ajxAttachFiles" name="fileUpload" type="file" style="display: none;"/>');
    if($("#ajxAttachFiles").length==0){
        elem.prependTo(".ChProgress");
    }

$("#ajxAttachFiles").on('click',function() {
  alert( 'click triggered' );
});

$("#ajxAttachFiles")[0].click();

//an alternative:
var event = new Event('click');
document.getElementById('ajxAttachFiles').dispatchEvent(event);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="ChProgress">Will be added here</div>

🌐
Apple Community
discussions.apple.com › thread › 2501915
Safari not responding to mouse clicks - Apple Community
July 11, 2010 - The only way to clear the problem is to close and restart Safari but then it only works for a short while before locking up again. Safari Version 5.0 (6533.16); Saft Version 12.1.0 PB 3 (8029); OSX 10.6.4; MacBook Pro 13in Thanks Paul ... You might want to consider starting a new discussion.
🌐
Reddit
reddit.com › r/applehelp › can’t click on anything when i open up safari on macbook (explained in comments)
r/applehelp on Reddit: Can’t click on anything when I open up Safari on MacBook (explained in comments)
April 10, 2018 - Close any existing windows, quit Safari, turn the network connection back on and then launch Safari. Hope that gets you out of the loop. ... replace $USER with your username, delete that file, it will recreate a factory default one on next launch ...
🌐
Shdon
shdon.com › blog › 2013 › 06 › 07 › why-your-click-events-don-t-work-on-mobile-safari
Why your click events don't work on Mobile Safari | blog | shdon.com
June 7, 2013 - In that case, tapping the clickable element (whether that click is a JavaScript onclick handler, or just a simple <a href="...">) does not register. Instead, it applies the :hover style and only on the second tap does it navigate or run the JavaScript. Here's a minimal testcase. As far as I've seen, this happens only on Mobile Safari, so try it with an iPhone or somesuch. Changing pretty much anything will make the bug disappear, so all of these are valid workarounds:
🌐
Apple Community
discussions.apple.com › thread › 252281774
Clicking on button on webpage does nothing - Apple Community
January 7, 2021 - I have noticed this occurring more often - I open a webpage, its url is fine, it's content is fine but when I go to click on a button which has an action which requires that to be done, Safari does nothing = I have to switch browsers and they are fine = this seems to happen with all sorts of websites and, honestly, I can't pinpoint when other than it's going on more often. [Mojave, Safari] ... Safari instantly closes tabs opened with cmd+shift+t in tabs group Hi, suddenly Safari started to immediately close tabs I reopened using cmd+shift+t in my tabs groups on my MacBook Air. It still works fine in the main tab group on Safari (the one that cannot be deleted and is always there).
Top answer
1 of 4
36

Speculating here, but will confirm later from a Mac. This has been confirmed to be working on a Mac.

Win ctrl+click or a Mac command+click gets picked up by a "normal" click listener, just like a click with any other modifier key (alt+click, shift+click etc).

This is particularly confusing since a ctrl+click on a Mac gets interpreted as a right-click on OS level. Command-click, on the other hand, is not interpreted as a middle-click but rather is a browser preference.

Assuming that you do not have in-site functionality that specifically relies on modified clicks, it would be appropriate to exclude such events from click listeners, and instead allow for them to bubble up to be natively handled by the browser. Given the experience of someone in the similar situation, you should be able to add the following to click handlers (likely a delegate on library level as pointed out by Brilliand):

if (e.metaKey || e.ctrlKey) return;

When added at the beginning of the handler with e referring to a current click event, this should circumvent any following e.preventDefault();

Update:

It actually works! In this rather minimalistic fiddle, I am able to recognize when command-clicked or control-clicked, so as to avoid executing the rest of the click handler which includes ajax-fetching the content and e.preventDefault();. This allows for a command-click to be handled "as intended" on a Mac, i.e. opening the link in a new tab.

With this finding in mind, these lines should now read

if (e.isDefaultPrevented() || e.metaKey || e.ctrlKey) {
    return;
}
2 of 4
7

There is some interesting insight here: https://groups.google.com/forum/#!msg/mozilla.dev.usability/H1qLTur4EFc/gXH007CAPk8J

Apparently the JS you are using can preventDefault() the cmd+click while the middle-click is unaffected. Consult the docs of your JS/Site framework.

🌐
Apple Community
discussions.apple.com › thread › 252762648
Using Command Click to Open a New Tab fro… - Apple Community
When you use the ⌘-click to open a search link in a new tab, it opens in the same tab as your search results disappear. We definitely understand how frustrating this could be, and we're glad to provide assistance. Keyboard shortcuts and gestures in Safari on Mac - Apple Support -- Since this should work, check your Safari settings.
🌐
SitePoint
sitepoint.com › javascript
Handling .click() in the Safari browser - JavaScript
April 28, 2023 - Tried various tricks like emulating touch event through a function: let clickEvent = new Event('click', { bubbles: true, cancelable: true, view: window }); Replace play.click(); with play.dispatchEvent(clickEvent); Added a style to all clickable ...
🌐
Reddit
reddit.com › r/macos › command + click not working on first try
r/MacOS on Reddit: Command + Click not working on first try
November 16, 2021 -

This is a repeatable bug for me on my M1 MacBook Pro 14" using Monterrey. Whenever I try to use Command + Click, say to open a link new tab, the first click does nothing. The second click does nothing. Only on the third click does something happen.

Edit: this happens specifically with tap to click. Personally, I always use tap to click, which seems like the more modern way to use a computer given that it resembles the way we interact with smartphones and tablets. But I realize this isn't the default so many people may not be noticing this bug. But it's infuriating. Imagine trying to tap on something on your iPhone in your first two tabs don't work. Or for everything on your computer to require three clicks to work.

Also, I've realized that this is not just restricted to Command + Click, but also Shift + Click and even just plain clicking on things in some instances (again, replace the word "click" with "tap," since that's how I have my trackpad set up).