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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T20:49:39+00:00 2026-05-12T20:49:39+00:00

So I’m sorry the title is so vague I’m not really even sure how

  • 0

So I’m sorry the title is so vague I’m not really even sure how to word this question in just a few words.

So I have a form for adding items to a webstore. Within that form is the option to add different varieties of a product, say different sizes or colors for clothing, etc…

I wanted to only offer a field for the first variety onload, then have an ‘add’ button to display an additional field for each further desired variety.

After you click the add button, the old add button becomes a subtract button, and a new input field as well as a new add button are appended to the previous.

I’d like this process to work continuously.

When adding the first new field, the process works perfectly, however, adding additional elements do not work as expected. The new fields are added as well as new add buttons, however the old add buttons are not converted to subtract buttons. I’m really not sure what the issue is here. I’m not exactly a jquery wizard.

Here’s the relevant part of the form:

<label for="varieties">Varieties</label><input type="text" name="varieties[]" id="varieties1" value="Default" /> <a href="#" class="add-variety"><img src="../img/plus.png" alt="Add" title="Add Another Variety" /></a><br />

And here’s the jquery that i’ve written:

    $('a.add-variety').click(function() {
    $(this).removeClass('add-variety');
    $(this).addClass('subtract-variety');
    $(this).append('<br /><input type="text" name="varieties[]" value="Default" /> <a href="#" class="add-variety"><img src="../img/plus.png" alt="Add" title="Add Another Variety" /></a>');
    $(this).children('img').attr('src','../img/minus.png');
    return false;
});

Thanks so much for any help!

  • 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-12T20:49:40+00:00Added an answer on May 12, 2026 at 8:49 pm

    Your “add variety” function is only bound to “.add-variety” element once, when the page is loaded. Any newly created “add variety” buttons don’t get any code bound to them, since they are created after the page has loaded. You might want to use the live function instead of click.

    Another problem, as you pointed out, is that you are appending additional lines inside your a element instead of afterward.

    I’d recommend wrapping the whole thing in a div tag to give you easy access to each line. This will allow you to remove some duplicate code by copying the HTML of an existing line, instead of including it again in your JavaScript code.

    Here’s my proposed version:

    <div>
         <label for="varieties">Varieties</label><input type="text" name="varieties[]" id="varieties1" value="Default" /> <a href="#" class="add-variety"><img src="../img/plus.png" alt="Add" title="Add Another Variety" /></a><br />
    </div>
    

    And jQuery:

    $(function() {
        $('a.add-variety').live('click', function() {
            $(this).removeClass('add-variety');
            $(this).addClass('subtract-variety');
    
            var parent = $(this).parent();
            parent.after($('<div />').html(parent.html()));
    
            $('img', this).attr('src','../img/minus.png');
        });
    });
    

    I’ve used $(string, element) instead of children to get access to the sub-image – I’m not sure if this will help with the minus-image problem, but I’ve found this form seems to work a bit better, since it includes all matching sub-elements of an element, not just immediate children.

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

Sidebar

Related Questions

this is what i have right now Drawing an RSS feed into the php,
I have just tried to save a simple *.rtf file with some websites and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Does anyone know how can I replace this 2 symbol below from the string
I have a bunch of posts stored in text files formatted in yaml/textile (from
I am trying to loop through a bunch of documents I have to put
I need to clean up various Word 'smart' characters in user input, including but

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.