+ 1
Help in JS
Was trying to change background color of table using js but failed to do so https://code.sololearn.com/Wm5CWhiI2qw0/?ref=app
2 Answers
+ 3
Delete onclick=ch() and type="button";
//Use
onload = ()=>{
//const btn = document.getElementById('btn');
btn.addEventListener('click', function onClick(event) {
const box = document.getElementById('tb');
box.style.backgroundColor = 'red';
});
}
Or:
function ch(){
tb.style.backgroundColor='red';
}
ES6:
ch=()=>tb.style.backgroundColor='red';
+ 2
You gave the button the id "btb" but in the code you use "btn"