Reputation: 307
I want to open a file dialog when the parent div is clicked. If I click the first parent div, it should only open the first input file.
<div class="fileupload">
<input type="file" class="file" name="image" />
</div>
<div class="fileupload">
<input type="file" class="file" name="attachement" />
</div>
Upvotes: 2
Views: 10511
Reputation: 5747
Try using trigger(),
$(document).ready(function() {
$(this).parents(".fileupload").find("input[type='file']").trigger('click');
});
Upvotes: 0
Reputation: 298532
Just trigger the click
event on the input
element:
$('.fileupload').click(function(e) {
$(this).find('input[type="file"]').click();
});
$('.fileupload input').click(function(e) {
e.stopPropagation();
});
Demo: http://jsfiddle.net/EctCK/
Upvotes: 10