Javascript language switch on same button -


i have part of code:

js:

function changetext() {     document.getelementbyid('lang').innerhtml = 'default language'; } 

html:

<p id='lang'>      other language      <input type='text' style="font-size: 12px;" onclick='changetext()' value='click me'/> </p> 

"click me" button works, , switches "default language" "some other language", disappears after initial click. able switch , forth languages on same button, able add button. ?

the problem replace whole inner html, whole content of p tag including button.

you want put content want replace in sub element, instance span:

<p>     <span id='lang'>some other language</span>     <input type='text' style="font-size: 12px;" onclick='changetext()' value='click me'/> </p> 

you can safely replace content of span because have no other needed html markup in there.

you can achieve same using additional javascript changing markup possibly easiest , clear solution.

hint: putting click handlers onclick attribute considered bad coding style. (why using onclick() in html bad practice?)


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -