I want to change valueto javascrip...">

How to change the value of an HTML element using javascript?

I have this: <input type="button" value="hello">I want to change valueto javascript so that it is value="goodbye". How to do it?

Following @David's recommendations in the comments below, this is the code I tried but could not modify before posting this question:

var createBttn = document.getElementById('create');
createBttn.innerHTML = 'value="goodbye"';
+3
source share
1 answer

First you need to get a reference to the object for which you want to change the value, and then assign a property to valuethis element, for example:

Say what your item had idfor "someButton":

var btn = document.getElementById('someButton');
btn.value = 'goodbye';
+5
source

Source: https://habr.com/ru/post/1771125/


All Articles