getElementById() returns null even though the element exists [duplicate] February 27, 2023 by Tarik You have to put this in a document load event. The DOM hasn’t gotten to abc by the time the script is executed.