Javascript: How do I refresh text values -


<script> function balancerefresher() {     <b>balance:      document.write(playerbalance)     </b>     } setinterval(balancerefresher, 1000); </script> 

obviously, isn't actual code, i'm trying refresh variable 'playerbalance' in text. have no idea other way in, complete beginner javascript.

document.write, name suggests writes document, if want dynamically modify , element on display create placeholder , access element , modify, example, in document create placeholder:

    <div id="any_id"></div> 

then in javascript:

    let el = document.getelementbyid("any_id");      if ( el ) {         if ( el.haschildnodes() ) {             el.removechild(el.childnodes[0]);         }         el.appendchild(document.createtextnode("your text"));     } 

https://www.w3schools.com/jsref/met_document_getelementbyid.asp


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -