Help in JS | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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

31st May 2022, 12:03 PM
Udith S M
Udith S M - avatar
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';
31st May 2022, 12:17 PM
Solo
Solo - avatar
+ 2
You gave the button the id "btb" but in the code you use "btn"
31st May 2022, 12:07 PM
Lisa
Lisa - avatar