Replace html code with other html code

hello i,m a newbie i want replace in a webpage html code with other html code using innerHTML
this is what i’m tryng to do:

function changeText3()
{
    var oldHTML=document.getElementById('esempio');
    
    var newHTML = 'Nuovo codice html';
    
if (oldHTML==oldHTML) 
       {
     document.getElementById('esempio').innerHTML = newHTML;
}
else
  {
document.getElementById('esempio').innerHTML = oldHTML;
}
     return false;
}

<div id='esempio'>Codice html</div>
<input type='button' onclick='changeText3()' value='Cambia Html'/>

This code work only at first click but i want that work also when i reclick
thanks

document.getElementById() returns a JavaScript DOM object, not an HTML string.

and how to modify my code?
thanks

Something like this?
http://codepen.io/ryanreese09/pen/pvGEdd

1 Like

yes!
thanks
it work

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.