mwbarry Posted August 21, 2011 Share Posted August 21, 2011 Why do I keep getting the error 'document.getElementById("content") is null'html <div id="content">old text</div> js document.getElementById("content").innerHTML = "new text"; Link to comment Share on other sites More sharing options...
Ixzion Posted August 21, 2011 Share Posted August 21, 2011 You need to show all of your code together. By itself, this is fine. Link to comment Share on other sites More sharing options...
Drycodez Posted August 21, 2011 Share Posted August 21, 2011 NB: the element you are targeting, should be on top , why the js should be at the bottom ! Link to comment Share on other sites More sharing options...
thescientist Posted August 21, 2011 Share Posted August 21, 2011 in other words. If you are going to have javascript execute on the page, and you are certain that the element exists, it's probably because your JS is running before the DOM has finished loading. If you are using jquery you can use $(document).ready(function(){}) or else use window.onload and make sure all your code is executing within na function assigned to window.onload instead. Let us know if none of that makes sense, lol. Link to comment Share on other sites More sharing options...
mwbarry Posted August 21, 2011 Author Share Posted August 21, 2011 in other words. If you are going to have javascript execute on the page, and you are certain that the element exists, it's probably because your JS is running before the DOM has finished loading. If you are using jquery you can use $(document).ready(function(){}) or else use window.onload and make sure all your code is executing within na function assigned to window.onload instead. Let us know if none of that makes sense, lol. perfect thanks! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.