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 notform
..?
Any help greatly appreciated.