/ Published in: JavaScript
Does an element exist in the current DOM tree?
Because I can never remember whether I should test typeof el == null... or el == null
Expand |
Embed | Plain Text
<div id="bar" /> <script> if (document.getElementById('foo') == null) { alert('foo is missing!'); } //or: if ( ! document.getElementById('bar')) { alert('bar is missing!'); } </script>
You need to login to post a comment.
