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 7847597
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T17:57:13+00:00 2026-06-02T17:57:13+00:00

Ok, i have input object, when it is changed it adds another one.. also

  • 0

Ok, i have input object, when it is changed it adds another one..
also there is delete (izdzēst) link when you click on, it should remove last input field..
how to that? (the function for delete is dzest )

I guess the problem is in $(this)?

<input name="userfile[]" type="file" size=40 />
&nbsp;<a href="#" onclick="dzest();return false" class="link" name="dzest" style="font-weight:normal; display:none;">Izdzēst</a><br /> 

<script>
function dzest(){
     $(this).closest('input').remove();
}
$("input[type=file]").change(function() {
    $('<input name="userfile[]" type="file" />').appendTo('body');
    $('<a href="#" onclick="dzest();return false" class="link" name="dzest" style="font-weight:normal; display:inline;">Izdzēst</a><br/>').appendTo('body');
    $('.link').css('display','inline');

});
</script>
  • 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-06-02T17:57:15+00:00Added an answer on June 2, 2026 at 5:57 pm
    • this in your code refers to the window object and not the anchor.
    • closest means the closest element parent, input can never be a parent, so you probably meant prev()

    Fixed Code

    $('<a href="#" onclick="dzest(this);return false" class="link" name="dzest" style="font-weight:normal; display:inline;">Izdzēst</a><br/>').appendTo('body');
    <a href="#" onclick="dzest(this);return false"
    

    And the function:

    function dzest(obj){
         $(obj).prev('input').remove();
    }
    

    You can also use unobtrusive event handlers & delegate events.

    $('body').on('click', '.link', function(){
            $(this).prev('input').remove();
        });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have input fields, which I process with AJAX and send it on another
So I have the function public Foo findVariable(Foo input) that returns an object of
I have JavaScript code that adds and removes classes using the classList object. The
I have a JavaScript input object with type="text" coming along with an onchange event
Currently I have Input: e.g., '123456789'.'+'.'987654321' Desired Pattern: Output: e.g., '123456789987654321' How can I
I have an arraylist set up. I have input instuctions set up too, so
How to rewrite Webconfig connection string at runtime.I have input textbox for Server,UserName and
I am working on templating system. I do have input of html document from
I have an input form with two textareas allowing a user to type in
I have an input type=file element with size=70 and width=522px . It looks and

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.