javascript - How to use same name tag to display innerhtml according to click? -


html

<div name="hhh" class="col-sm-7  new" align="left" >  </div> 

javascript

yes.onclick =function() { var = document.getelementsbyname("hhh");     for(var = 0, max = all.length; < max; i++)          {             all[i].innerhtml="you have clicked yes.";          }  }   no.onclick =function() { var = document.getelementsbyname("hhh");     for(var = 0, max = all.length; < max; i++)          {             all[i].innerhtml="you have clicked no.";          }  } 

here in html 2 buttons there yes , no.if user clicks yes,yes.onclick() execute , if user clicks no,no.onclick() execute. in same division hhh, have display message according click. if write above code,the message displayed before click. considering hhh 1 name. how can edit code, display message according click? right on writing existing message.i dont want on write.i want display previous message also.

u should use getelementsbytagname() or better u should use getelementbyid if have 1 div.

where assign name "yes" , "no" js var? maybe problem that. if there no reason assign function dinamically code can define 1 function

function myerror(e){     var = document.getelementsbytagname("hhh");         for(var = 0, max = all.length; < max; i++)          {             all[i].innerhtml="you have clicked " + e.value;          } } 

then assign function ur button

<input type="button" value="yes/no" onclick="myerror(this)"> 

Comments

Popular posts from this blog

wireshark - USB mapping with python -

c++ - nodejs socket.io closes connection before upgrading to websocket -

Deploying Qt Application on Android is really slow? -