javascript - Need help changing appendChild to replaceChild -


is there easy way change appendchild replacechild?

this of course continuously adds more ele. reason doesn't put value inside div or span, seems put below it.

var para = document.createelement("p"); var total = document.createtextnode(parsefloat((subt + tax).tofixed(2))) ;  para.appendchild(total);  document.getelementbyid("total_id").appendchild(para); 

its updating this:

<div class="prod_totals">order total: $<span id="total_id"></span></div> 

you can use innerhtml instead of appendchild

document.getelementbyid("total_id").innerhtml = parsefloat((subt + tax).tofixed(2)); 

because you're not inserting user input values inside total_id element , far question mentions, data not later passed server think you'll safe using innerhtml here. if reasons you'd still use replacechild this:

var para = document.createelement("p"); var total = document.createtextnode(parsefloat((subt + tax).tofixed(2))) ;  para.appendchild(total);  var existingtext=document.getelementbyid("total_id").queryselector('p'); if(existingtext){     document.getelementbyid("total_id").replacechild(existingtext, para); } else{     document.getelementbyid("total_id").appendchild(para); } 

Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -