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

  • Home
  • SEARCH
  • 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 7604029
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:48:14+00:00 2026-05-30T23:48:14+00:00

Below is part of the jquery code I have which displays the file input

  • 0

Below is part of the jquery code I have which displays the file input and a “Clear File” button.

var $imagefile = $('<input />')
    .attr({
        type: 'file',
        name: 'imageFile',
        class: 'imageFile'
    });

$image.append($imagefile);

var $imageclear = $('<input />')
    .attr({
        type: 'button',
        name: 'imageClear',
        class: 'imageClear',
        value: 'Clear File'
    });

$(".imageClear").click(function(event){
  event.preventDefault();
  $(".imageFile").replaceWith("<input type='file' class='imageFile' />");
});

Now if you look at the bottom of the jquery code, it shows a function I am using where if the user clicks on the “Clear File” button, it replaces the file input so that if you have chose a file but then want to clear the input, then it does this by replacing the input.

The problem though is that lets say I have two “imageFile” inputs (each file input contains its own “Clear File” button” and they both contain a file, then lets say I want to clear the first file input only, when I click on the “Clear File” button, it clears both file inputs, even though I only want it to clear one file input. So how do I code it so that each “Clear file” button only clears the file input it belongs to?

  • 1 1 Answer
  • 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-05-30T23:48:15+00:00Added an answer on May 30, 2026 at 11:48 pm

    Supposing the input and the button are inside the same container (es.div), change that line to:

    $(this).parent().find(".imageFile").replaceWith("<input type='file' class='imageFile' />");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Below is part of the jquery code I have which displays the file input
I have the below code in my .aspx page. <input type=hidden id=fbinfo name=fbinfo value=
below is part of html code <div id=test1><span><input type='text' name='add'/><input type='text' name='del'/><span></div> <div id=container></div>
I have a code setup something like below, the image is part of a
I have the jquery code below that returns a list of ID's like this
Below is part of the XML which I am processing with PHP's XSLTProcessor :
Below, I inserted a code written by Ray Konopka (part of the Coderage presentation).
Why is an exception being thrown in the f++ part of the code below
I have the below code that does not seem to work at all :(
I am using the jQuery autocomplete plugin and have wired up an input field

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.