Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8296739

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T15:08:12+00:00 2026-06-08T15:08:12+00:00

Im using JQuery to check the file size and name from an html file

  • 0

Im using JQuery to check the file size and name from an html file input field. The input field is:

<div id="uploadFile_div">
    <input name="source" id="imageFile" type="file" style ="border: 1px solid #576675;">
</div>

And the JQuery:

$(document).ready(function(){

    $('#imageFile').bind('change', function() {

    alert("Test");
    //.... perform input checks...//

    });   
});

Now, I have a selection box, where the user choose between image file or video file, and based on it I send the file to different servers and also perform appropriate checks. In order to reset the input field (I do it when the user changes the selection box from Video to Image and vise versa) I use this JavaScript trick:

document.getElementById('uploadFile_div').innerHTML = document.getElementById('uploadFile_div').innerHTML;

But After 1 execution of this JavaScript, The JQuery isn’t binded and I don’t see the “Test” alert when I select files.

How can i rebind the JQuery ?

Thanks.

  • 0 0 Answers
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T15:08:14+00:00Added an answer on June 8, 2026 at 3:08 pm

    You could use a delegated event handler, binding the event to the parent div:

    $('#uploadFile_div').on('change','#imageFile', function() {
       // etc
    

    Demo: http://jsfiddle.net/SfgpS/

    (If you’re using a version of jQuery older than 1.7 use .delegate() instead of .on(). If you’re using a really old version of jQuery use .live().)

    When you rewrite the .innerHTML of the container that effectively erases the old input element including event handlers that were bound to it, and then creates a new input. So you could re-run your original .bind() statement at that point to bind a handler to the new input.

    With a delegated event handler as for that syntax of .on() you bind the handler to the container, i.e., to the div in this case. Events that happen to the container’s child(ren) bubble up to the container (and then right on up to the document). So in this case when a change event reaches the div jQuery checks whether it originated with an element matching the selector from the second parameter of .on() and if so calls the your handler function. This lets you handle events on elements that don’t exist at the time you create the handler. It doesn’t matter if you remove and re-add the child elements because the handler was bound to the container.

    (Note that if you leave out that second parameter to .on() it creates a non-delegated handler just the same as .bind().)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using jquery or JS how do i check if an object is a div
I'm using the JQuery DropdownChecklist as available from here: http://code.google.com/p/dropdown-check-list/ Basically I'm using some
I am using jquery UI tab for my project. Kindly check the html code
I have a javascript file that Select a button using jQuery and check it
I've got a simple HTML file upload form. I'm using the jQuery validation plugin
i want to check the type of uploaded file. If name like example.txt ,
How to check visited link using jquery without using any plugin please help to
How do I check if browser supports position:fixed using jQuery. I assume I have
How do you check if there is an internet connection using jQuery? That way
I have problem while using jquery maskedinput with asp.net textbox. I have a check

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.