JQuery, cannot change the ID of a cloned element? -
is there issue updating id's of cloned elements? think syntax correct here it's not updating.
function addquestion(){ // clone first question container , give new id $('#questioncontainer0').clone().attr('id','questioncontainer'+currentquestion).appendto('#questionarea'); // assign new id text area field (this not working) $('#question0').attr('id','asdasd'); var test = $('#question0').attr('id'); alert(test); } question0 child element (textarea) of original cloned questioncontainer0 (div)
change
$('#question0').attr('id','asdasd'); to
$('#question0', '#questioncontainer'+currentquestion).attr('id','asdasd'); this restrict search inside cloned elements only.
and more sure, should before appending cloned elements in dom, since ids supposed unique in dom.
function addquestion(){ // clone first question container , give new id var newelement = $('#questioncontainer0').clone().attr('id','questioncontainer'+currentquestion); newelement.find('#question0').attr('id','asdasd'); newelement.appendto('#questionarea'); }
Comments
Post a Comment