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>
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/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With