Answer the question
In order to leave comments, you need to log in
How to handle "object may be null" when getting elements via querySelector/getElementById/etc?
Of course you can write something like: document.querySelector(`elmentname`) ? .classList.add("disabled")
But I would like to get an error if the element is not found, if for example I specified a wrong selector.
What would the compiler not swear and throw an exception when calling .classList.add("disabled") ?
How to do it right?
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question