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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:04:15+00:00 2026-05-27T07:04:15+00:00

I have a simple form, where each line consists of 3 input fields. on

  • 0

I have a simple form, where each line consists of 3 input fields. on one of those fields, I use jscolor.js (field has a class="color" and thus binds the JS).

However, when I add new lines using jQuery’s delegate(), the input field doesn’t bind the JS and the expected functionality is not there. http://jsfiddle.net/alexwald/qARzP/

<script>
var line = '<li class="form_line" id="line">    
              <span>
                <label for="item">Item:</label>
                <input type="text" required="required" placeholder="what item is this?" id="item" name="item[]>
              </span>
              <span>
                <label for="amount">Amount: </label>
                <input required="required"  type="number" id="amount" name="amount[]>
              </span>
              <span>
                <label for="color">Color: </label>
                <input type="text" required="required" class="color {pickerClosable:true, hash:true ,pickerFace:3,pickerBorder:0}" id="color" name="color[]">
              </span>
            </li>';

$(document).ready(function() {          
  $("form").delegate(".add", "click", function(){        
    $('ul').append(line); 
  }); // end of adding                              
}); //end of main func 
</script>

I think the problem is either in:

  • how I define the line variable, or
  • I’m using an improper selector with .delegate, so it should be something else and not form..?

Any help greatly appreciated.

  • 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-27T07:04:16+00:00Added an answer on May 27, 2026 at 7:04 am

    There are several problem to your code:

    1. You are using IDs in your “line” variable. ID must be unique within an HTML document. You’d better use name attributes, or create a new line differently so you can change the IDs.

    2. Why do you delegate the ‘click’ event for the ‘Add’ button ? Event delegation is used be able to automatically “bind” events to elements created dynamically. In your example, the “Add” button, is static to the page, you don’t need to use delegate, simply .click() or .bind().

    3. After creating the new line, you have to explicitly initialize your jscolor on the new field, it’s not going to happen automatically. When your page is first parsed, the existing <input class="color" /> are initialized by the jscolor plugin, but insterted elements afterwards are not anymore, the script has run already.

    Here’s some modified code:

    <script> 
        var line = '<li class="form_line" id="line"><span><label>Item:</label><input type="text" required="required" placeholder="what item is this?" name="item"></span><span><label>Amount: </label><input required="required" type="number" name="amount"></span><span><label>Color: </label><input type="text" required="required" class="color {pickerClosable:true, hash:true ,pickerFace:3,pickerBorder:0}" name="color"></span></li>';
    
        $(document).ready(function() {
    
           var $ul = $('#formulario'); // the UL, select it once and r-use this selection
    
           $('.add').click(function(e) {
               var $line = $(line);
               $line.appendTo($ul);
    
               // initialize the new jscolor instance
               new jscolor.color($line.find('input[name=color]')[0], {});
    
           });
    
    
        }); //end of main func 
    </script>
    

    And this jsfiddle for testing.

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

Sidebar

Related Questions

I have text in the form of separate lines, where each line has CSV-like
I have an a windows form application that use one class (its name is
I have simple form. <form target=_blank action=somescript.php method=Post id=simpleForm> <input type=hidden name=url value=http://...> <input
Have a simple form (only extract fields here) but for some reason the JQserilization
I have a simple form with some plain html input like bellow using ASP.NET
I have a simple form like this: <form name=serachForm method=post action=/home/search> <input type=text name=searchText
Say I have this simple form: class ContactForm(forms.Form): first_name = forms.CharField(required=True) last_name = forms.CharField(required=True)
I have have a simple HTML form with say four input widgets (see below)...two
I have a simple Django form: class CommentForm(forms.Form): comment = forms.CharField(max_length=2000, required=True) post_id =
I have a simple form on a view page, implemented as a user control,

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.