Skip to content Skip to sidebar Skip to footer

Jquery .click() Does Not Work In Safari

I have seen several similar posts with solutions that seemed to have worked for those people, but I CANNOT get this to work. I am using http://tutorialzine.com/2013/05/mini-ajax-fi

Solution 1:

The second section of code in my original question turned out to work, except for 2 things.

1) The method does not like jQuery, so instead of

var a = $(this).parent().find('input')[0];

I assigned an ID to my file input and instead called

var a = document.getElementById('upload_select');

2) Safari blatantly ignores this if the input is hidden (display:none;), which is was, so instead I made the input font-size = 1px; and opacity = 0.

Implementing these two changes got the code working.

Solution 2:

You need to read that answer more closely. :-)

dispatchEvent is a function on the DOM element, not the jQuery object. You're trying to call it on the jQuery object. So:

$('#drop a').click(function(){
    var a = $(this).parent().find('input')[0];
    // Change here -----------------------^^^var evObj = document.createEvent('MouseEvents');
    evObj.initMouseEvent('click', true, true, window);
    a.dispatchEvent(evObj);
});

Using the [0] on the jQuery object gives you the first DOM object in the jQuery object, or undefined if the jQuery object is empty.

Post a Comment for "Jquery .click() Does Not Work In Safari"