How to change the "code" content of a section with javascript [closed]

-2

Hi, I need to change the content (code) of a section with javascript with the .click or onClick function but the content can not override that of the other section! Thanks

    
asked by anonymous 11.07.2016 / 15:10

1 answer

1

If I understood correctly what I want, I think this is it:

var btn = document.getElementById('btn-sect1');
var sect1 = document.getElementById('sect1');
btn = btn.addEventListener('click', function() {
  sect1.innerHTML = '<h1>Agora já não é o original</h1><p>Está aqui outro codigo html</p>'
});
<section id="sect1">
  <h1>Aqui está o codigo original da sect1</h1>
</section>
<section id="sect2">
  <h1>Aqui está o codigo original da sect2</h1>
</section>
<button id="btn-sect1">Mudar HTML da sect1</button>
    
11.07.2016 / 15:26