document.addEventListener('DOMContentLoaded', () => { const questionsContainer = document.getElementById('questions-container'); const addQuestionButton = document.getElementById('add-question-button'); addQuestionButton.addEventListener('click', () => { const questionCount = document.querySelectorAll('.question-block').length; const questionBlock = document.createElement('div'); questionBlock.className = 'question-block mb-4 p-4 bg-gray-50 rounded-lg shadow-inner'; questionBlock.innerHTML = `
`; questionsContainer.appendChild(questionBlock); addOptionButtonListener(questionBlock.querySelector('.add-option-button')); }); document.querySelectorAll('.add-option-button').forEach(button => { addOptionButtonListener(button); }); function addOptionButtonListener(button) { button.addEventListener('click', () => { const questionBlock = button.closest('.question-block'); const optionsContainer = questionBlock.querySelector('.options-container'); const optionCount = optionsContainer.querySelectorAll('.option-block').length; const optionBlock = document.createElement('div'); optionBlock.className = 'option-block mb-1 flex items-center'; optionBlock.innerHTML = ` `; optionsContainer.appendChild(optionBlock); addRemoveOptionButtonListener(optionBlock.querySelector('.remove-option-button')); }); } document.querySelectorAll('.remove-option-button').forEach(button => { addRemoveOptionButtonListener(button); }); function addRemoveOptionButtonListener(button) { button.addEventListener('click', () => { const optionBlock = button.closest('.option-block'); optionBlock.remove(); }); } });