Monday 18 December 2017

javascript - document.getElementById() doesn't work?





No much to
say,








onclick="alert('1')" />






The
alert message is null instead of a message contain details of
the object or something like that.



What is the
problem?



Answer




Put your script AFTER the actual element,
otherwise by the time your javascript code runs, there's not yet such element in the
DOM.







onclick="alert('1')" />






Alternatively
put your script in a DOM ready event to ensure that the DOM is fully loaded by the
browser before attempting to manipulate
it:








value="Clickme" onclick="alert('1')" />






No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...