views:

365

answers:

2

How do I specify label to Checkbox that is added thru the JQuery Clone(false) method and does not have a Unique id ?

+1  A: 

The label needs something to link it with the checkbox. Hence, you need to add a unique ID to the checkbox and use this to relate the label.

I'd use something to count the number of checkboxes, increment this count and use it to ensure your ID is unique.

var checkCount = $("input[type='checkbox']").length;
var newCheckbox = $(oldCheckBoxID).clone(false).attr("id", "checkbox" + checkCount);
var newLabel = $("<label />").attr("for", "checkbox" + checkCount).html("label text");
daddywoodland
A: 

Thanks a lot for ur answer... but I dnt want to have unique ids in my page... I have accessed everything thru names... just to add labels I dnt want to use unique ids...