Any ideas as to why the ID and Name are not updating here?
function addQuestion(){
var currentQuestion = $(".questionContainer").size(); //Number of questionContainers
var $newElement = window.$pQuestion.clone().attr('id','questionContainer'+currentQuestion);
$newElement.children('#question0').attr('id','question'+currentQuestion).attr('name','quest ion'+currentQuestion);
//Update the answerContainer div id.
$newElement.children('#answerContainer0').attr('id','answerContainer'+currentQuestion);
//Update the first answer id and name
var answerId = 'question'+currentQuestion+'-answer1';
$newElement.children('#question0-answer1').attr("id",answerId).attr("name",answerId);
$newElement.appendTo('#questionArea');
}
The last few lines is where the issue seems to be. This should update to “question1-answer1” I have verified that the value of answerId is correct, just seems to not be applied to the ID and Name.
Let me know if you’d like more context.
Is the
#question0-answer1an immediate child of the.questionContainerin the DOM ?Or might it be nested deeper ? in which case you would need to use
update
seeing the posted code, indeed your element is not a child but a descendant, so use the suggestion above..