Doubt for an activity

3

3) Make a Javascript code that changes the value of the text element content to "Pedro Brigatto".

I have to change the value of this value in this input:

<!DOCTYPE html>
<html>
  <body>
    <input type="text" id="myText" value="Mudar aqui">
  </body>
</html>
    
asked by anonymous 29.10.2017 / 20:05

2 answers

5

The code could be this:

document.getElementById("myText").value = "Pedro Brigatto";

document.getElementById("myText").value = "Pedro Brigatto";
<input type="text" id="myText" value="Mudar aqui">
    
29.10.2017 / 20:13
4

For you to select an HTML element in JavaScript, seven your field with an ID, if you use it once, as done in your code:

<input type="text" id="myText" value="Mudar aqui">

In this case, your ID is "myText".

In JavaScript, you need to get this data and set it, just like @DVD did in the previous answer, but who does this for you is:

document.getElementById("AQUI VAI O SEU ID");

When you place the .value after this code, you are getting the value of your input field. You can pick up other parameters, as I'll give you some examples below:

Change the class parameter:

document.getElementById("myText").class = "Pedro Brigatto";

Change the id parameter:

document.getElementById("myText").id = "Pedro Brigatto";

I hope I have contributed to your knowledge! :)

    
29.10.2017 / 20:22