Ask your JavaScript questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

code modified so as to have zero listeners JavaScript


Original post is at

I would like to have this js code modified so as to have zero listeners. I need a function to be called from the input: <input type="file" id="fileInput" onchange = "myNewFunction();" />

<input type="file" id="fileInput" />

// load file content from input
(function() {

// find the input by id
const fileInput = document.querySelector( "#fileInput" );

// listen for change
fileInput.addEventListener( "change", function() {

// check if a file has been selected
if ( this.files && this.files[0] ) {

const reader = new FileReader();

// wait for the contents of the file to be loaded
reader.addEventListener( "load", function( e ) {

// file data
const fileContent =;
alert( fileContent );

// load selectd file
reader.readAsBinaryString( this.files[0] );

Answers (1)


Rainner Lins answers:

If it doesn't work, try loading the JS before the html.