I can not change the contents of my button

0

I'm trying to change the text of my button when I click on it, but I'm not getting it.

My code:

function altera(argument) {
    document.getElementById('novo').innerHTML="atualizou";	
}
<!DOCTYPE html>
<html>
 <head>
  <title>noono</title>
  <script src="intercao.js"></script>
 </head>
 <body>
 <button id="novo" onclick="altera()">Isso e um teste</button>
 </body>
</html>
    
asked by anonymous 27.10.2018 / 17:13

1 answer

3

Use the textContent property for this:

function altera(argument) {
  document.getElementById('novo').textContent ="atualizou";    
}
 <button id="novo" onclick="altera()">Isso e um teste</button>

innerHTML is using to include content html with tags, in your case it's just the text inside a button, so you can use textContent .

The innerText property has the same "semantic" function, that is, change the text and not html content. Although it is not standard, it is used in Internet Explorer , so if you have problems you can check which one to use.

    
27.10.2018 / 17:19