+ 1

try to make the button disabled but error

i am making disabled button with disabled property in javascript but why error please explain to me why this error happened https://code.sololearn.com/W8WI0xpdfdh7/?ref=app

15th May 2018, 1:07 PM
Hafizd Jubaidir
Hafizd Jubaidir - avatar
3 Answers
+ 7
Because you element doesn't exist const rButton; window.onload = function() { rButton = document.getElementById("removeBtn"); rButton.disabled = true; }
15th May 2018, 1:17 PM
Toni Isotalo
Toni Isotalo - avatar
+ 1
You must make sure that DOM is avaible at getElementById time else any call for get elements references return null.... Try to wrap your js code in a function that set like window onload listener: window.onload= function(){ // your js code here }
15th May 2018, 1:15 PM
KrOW
KrOW - avatar
+ 1
when i use window.onload html can not access function
15th May 2018, 1:19 PM
Hafizd Jubaidir
Hafizd Jubaidir - avatar