I am not sure if title says what correctly I am trying to do but I don't know how to name that problem.
I am trying to add some style to input[type="file"] element using css and jquery. Here is my code:
<div class="input-file">
<input type="file"><label>Select file...</label><button type="button">...</button>
</div>
where INPUT has display: none style so it's not visible.
Javascript:
$('.input-file > button').live('click',function() {
$('input[type="file"]').click(); });
It works good if only 1 element is on page but if there are for example 3, whenever I click on button 1, it will fire function 3 times. I would like it to respond only for it's parent element which is <div class="input-file">
How could I use .parent or .before or whatever function can work to achieve this?
EDIT:
@Chandu has a great solution.
Also, another alternative would be $(this).prev().prev().click(); if elements are static and always in the same position.
Thank you @Chandu.