Reputation: 23317
I'm generating text fields using jquery. And I'm using jquery ui to style the form. My problem is that the dynamically generated elements, doesn't get the css of jquery ui:
var index = 0;
$('#btn_generate').live('click', function(){
var tr = $("<tr>").appendTo('#tbl_body');
var td = $("<td>").appendTo(tr);
var txt = $("<label>").attr({'for' : index}).appendTo(td).html('content' + index + ':').css({'color' : 'white'});
$("<input>").attr({'type' : 'text', 'name' : 'field[]', 'id' : index}).appendTo(td);
index++;
});
How do I solve this one?
Upvotes: 2
Views: 1790
Reputation: 6969
I'm guessing you're getting jQuery to style the form initially on document ready?
If so, you have two options...
If I'm barking up the wrong tree let me know :)
Upvotes: 2
Reputation: 1402
you can try something like this:
var index = 0;
$('#btn_generate').live('click', function(){
var tr = $("<tr>").appendTo('#tbl_body');
var td = $("<td>").appendTo(tr);
var txt = $("<label>").attr({'for' : index}).appendTo(td).html('content' + index + ':').css({'color' : 'white'});
$("<input>").attr({'type' : 'text', 'name' : 'field[]', 'id' : index}).appendTo(td);
//as you have given id=index to your input
$('#'+index).yourjqueryuifunction();
index++;
});
Upvotes: 1