jQuery 'trigger('click')` not working on opera if the element is not displayed
Asked Answered
V

2

5

I have some element which click on it event triggers click on <input style="display:none" type="file"/> element. this element is hidden (display:none). On this browser: Chrome, IE, FireFox it is working (the trigger executes) but on Opera and Safari it doesn't. Is there any special thing I need to do for the problematic browsers (Opera and Safari)? Is there any walk around?

Many thanks!

here is the code of the event

$('#add_cv').click(function(){
   $('#add_cv_input').trigger('click');
});
Vintner answered 14/10, 2012 at 8:42 Comment(1)
Can you show the code that you have written?Constantine
V
10

Ok I found this workaround, I have set the element's css to:

visibility: hidden;
position: absolute;
top:0;

it is working on every browser above. I will be more than glad to hear any other solutions.

Vintner answered 14/10, 2012 at 8:49 Comment(2)
The element will just be transparent, not clickable and (eventually) on the top of the page. Any links or buttons below it can't be clicked.Ultrasonic
I would just make the top and left values negative and then it shouldn't cover anything.Allisan
U
5

Use the following as an alternative to display: none:

position: absolute;
top: 0;
left: -9999px;
Ultrasonic answered 14/10, 2012 at 10:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.