javascript - Using document.write removes all other text and displays only the message -




i have question how make there button in 1 column , when click button, text appears in column. overall goal make simple clicker.

here code:

<html lang="en">     <head>         <meta charset="utf-8" />         <title>clicker</title>         <meta name="generator" content="bbedit 11.6" />     </head>     <body>         <table width=600>             <tr>                 <td width=300><span><font size=24px><button onclick='onclick()'>                     click me                     </button></span></td>                 <td sidth=300><span><font size=24px>so this</span></td>             </tr>         </table>     <script>         clicks = 0;              function onclick () {                 clicks = (clicks + 1);                 document.write ("you have clicked button ")                 document.write (clicks)                 document.write (" times")             };          </script>     </body> </html>  

i have need make message when click button, when do, other text dissipears , message. tell me if stupid mistake or not please. need know.

to show count of clicks in page, , keep html, simple way achieve adding div , manipulate content getelementbyid (to element) , call innerhtml (to change content of html element).

add bellow html table:

<div>   <h1 id=click-event> </h1>    </div> 

and change onclick():

function onclick () {   clicks = (clicks + 1);   document.getelementbyid("click-event").innerhtml = "you have clicked button " + clicks + " times"; }; 




wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -