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

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -