Add an erase feature to the drawing program below code . Try setting the backgro
ID: 3534259 • Letter: A
Question
Add an erase feature to the drawing program below code. Try setting the background color of the table cell over which the mouse moved to white when theAlt key is pressed <!DOCTYPE html>
<!-- draw.html -->
<!-- A simple drawing program. -->
<html>
<head>
<meta charset="utf-8">
<title>Simple Drawing Program</title>
<link rel = "stylesheet" type = "text/css" href = "style.css">
<script src = "draw.js"></script>
</head>
<body>
<table id = "canvas">
<caption>Hold <em>Ctrl</em> (or <em>Control</em>) to draw blue.
Hold <em>Shift</em> to draw red.</caption>
<tbody id = "tablebody"></tbody>
</table>
</body>
</html>
Explanation / Answer
function erase() {
// Get all of the TDs inside of my table body
var allTDs = document.getElementById("tablebody").getElementsByTagName("td");
// Loop over them all
for (i = 0; i < allTDs.length; i++) {
// Set the background color to white
allTDs[i].style.backgroundColor = "white";
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.