My friend advised me to do it differently:
<a class="btn btn-primary" href="#" style="margin-left: 100px" id="prefix">Choose file</a><input type="file" id="file_source" style="position:absolute;z-index:2;top:0;left:0;filter:alpha(opacity=0);opacity:0;background-color:transparent;color:transparent;">
Make a separate a and type and then trigger the click event
jQuery("#prefix").click(function() { console.log("INSERT JSON"); $("#file_source").click(); return false; });
source share