Try the following:
HTML
<form action="/action_page.php" method="get" name="form1"> <input type="text" id="campoDeFlores"> <button type="button" onclick="changeColor(this)" name="1">1</button> <button type="button" name="2">2</button> <button type="button" name="3">3</button> </form>
Js
function changeColor(btn) { btn.style.backgroundColor = "green"; }
Check out this script .
Explanation
At first, I thought you were trying to change the color of all buttons because you used
getElementsByTagName , but it looks like you just want to change the color of the button that was pressed. In this case, you do not need to use an array. Just pass in the element that was clicked on the function, and then change the color of the specific button.
source share