There is a coding challenge involving a checkbox
and a div
. When the checkbox
is checked, the max-width
attribute of the div
should decrease (causing it to shrink in size), and vice versa.
function adjustTableWidth(checkbox) {
var table = document.getElementById("table-mark");
alert(checkbox.checked);
if (checkbox.checked === true) table.style.maxWidth = "600px";
}
#marks-table {
overflow-x: scroll;
/*max-width: 600px;*/
border-right: 1px solid #ddd;
border-left: 1px solid #ddd;
}
<input type="checkbox" id="check" onclick="adjustTableWidth(this)">
<div id="marks-table" style="max-width: 900px">
In this scenario, when the checkbox
is checked, the width of the div
should be set to 600px
, and when unchecked, it should revert back to 900px
.
The alert in the JavaScript function triggers as expected, but there seems to be no visible change in the div's size.