MCQs > IT & Programming > JavaScript > Which will toggle a div element's background color?
Change Background Color.

JavaScript MCQs

Which of the following code snippets will toggle a div element's background color? <button id="toggle">Toggle</button> <div id="terd">Change Background Color.</div>

Answer

Correct Answer: <script> var button = document.getElementById('toggle'); button.onclick = function() { terd.style.backgroundColor = terd.style.backgroundColor == 'blue' ? 'red' : 'blue'; }; </script>

Explanation:

Note: This Question is unanswered, help us to find answer for this one

JavaScript Skill Assessment

Overall Skill Level-Poor

Your Skill Level: Poor

Retake Quizzes to improve it

search

JavaScript Skill Assessment

Overall Skill Level-Poor

Your Skill Level: Poor

Retake Quizzes to improve it