div에 복제하고 다른 div (부모)에게 추가하려고합니다. 나는 이것을 위해 clonenode를 사용하고 있지만 작동하지 않는 것 같습니다. 첫 번째 함수에서 div를 복제하고 두 번째 함수에서 div의 부모에 추가합니다! 내가 뭘 잘못하고 있는지 모르겠다. 이 여기에 코드입니다 (* 편집 : * var에 추가) : 여기에 라이브cloneNode를 사용하여 여러 div를 복제 할 수 있습니까?
function cloneQ() {
//Cloning questions and shit
cloneQ.id = (cloneQ.id || 0) + 1;
var question = document.getElementById("question");
var clone = question.cloneNode(true);
var numberOfQuestions = $('.question').length;
var id = "questioncon" + cloneQ.id;
clone.id = id;
question.parentNode.appendChild(clone);
var inid = "question" + cloneQ.id;
var optionid = "optionsdiv" + cloneQ.id;
$('#' + id + ' ' + '.' + 'questionin').attr('id', inid);
$('#' + id + ' ' + '.' + 'options').attr('id', optionid);
$('#' + id + ' h2').html('Question ' + cloneQ.id);
//Question Cloned
}
function cloneforPrint() {
cloneforPrint.id = (cloneforPrint.id || 0) + 1;
var questionprint = document.getElementById("questionprint");
var cloneprint = questionprint.cloneNode(true);
var printid = "questionprint" + cloneforPrint.id;
cloneprint.id = printid;
questionprint.parentNode.appendChild(clone);
var printinid = "thequestionprint" + cloneforPrint.id;
$('#' + printid + ' ' + '.' + 'thequestionprint').attr('id', printinid);
}
제발 DOM과 jQuery를 섞지 마십시오. ** 제대로 들여 쓰기! ** – ThiefMaster
왜 그래? 내가 사용한 몇 줄의 jQuery는 Javscript에서 더 어려울 것입니다. – jackson5
코드를 이해하려고 할 때 상황 전환을 강요하는 것은 좋지 않습니다. jQuery에서 모든 작업을 수행하거나 jQuery없이 모든 작업을 수행하십시오. –