javascript - JS Function calling displaying odd text & not working more than once -


i have problem, when run function "addmoney(amount)" (shown below) works , shows following: 100[object htmlbuttonelement]

my question this, there way rid of [object htmlbuttonelement] while keeping number moneyamount when function called? , additionally, there way call function multiple times , add money accordingly? works first time call it, calling more once same or different amounts of moneyamount displays no more or no less displays first time.

my html:

<li class="item_shown" id="money">shrill:  <button class="moneybutton" id="moneyamount">0</button></li> 

calling function in html:

<a class="button" onclick="javascript:addmoney('100');">add 100 money</a> 

my js function:

function addmoney(amount) { document.getelementbyid('moneyamount') var newbalance = amount + moneyamount; document.getelementbyid('moneyamount').innerhtml = newbalance; }  

the text inside element considered text node , since button node has no other children, button node's first child. text node's value (in case "0") value of nodevalue property. assigning new value nodevalue change text displayed. in case following code should work:

function addmoney(amount) {   var node = document.getelementbyid('moneyamount');   var textnode = node.childnodes[0];   var moneyamount = parseint(textnode.nodevalue, 10);   textnode.nodevalue = amount + moneyamount;} 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -