javascript - Js, document.getElementById("ID").innerHTML, error -


hello i'm new javascript, , i'm try write out code test site , i'm having problems, dow below code , keep getting error , can't figure out why.

typeerror: null not object (evaluating 'document.getelementbyid("h3").innerhtml = "<h3>you date!</h3>"')

this second method tried using. i'm trying have have version list first 1 had pull .js file , build table, didn't work thought try this, guess happened? not working

my code i'm using below. if can amazing. thanks, dakmessier

var current = "1.0"; function get_latest(){ document.getelementbyid("bob").innerhtml = current; }  if (local != current){ document.getelementbyid("get").innerhtml = "<button><a href=\"bla\">get latest update!</a></button>"; } else if (local == current){  document.getelementbyid("h3").innerhtml = "<h3>you date!</h3>"; } else { document.getelementbyid("h3").innerhtml = "<h3>sorry, unable check update.</h3>"; } 

document.getelementbyid(id) finds element given id value in html. id value looks this:

<div id="myheader">some content</div> 

and, can find element with:

document.getelementbyid("myheader"); 

id values must unique in each document there should ever 1 element given id.


if id isn't want, can find elements other ways, tag type, class name, attribute, etc... using css selectors document.queryselectorall().

for example, if wanted find <h3> tags, this:

var items = document.queryselectorall("h3"); 

here other reasons document.getelementbyid(...) might fail find want find:

  1. the javascript code running before dom elements have been parsed , loaded element not there yet when you're running code. common code run <head> section of document.

  2. you have html error in how specifying id value in html.

  3. you have html error causes browser not parse html properly.

  4. you have script error cause script abort before gets part want run.


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -