12

Using javascript (preferably not jquery) I'm trying to change the line:

<input type="number" name="price" required="" id="id_price">

into

<input type="number" name="price" required="" id="id_price" step="any">

I know the solution's got to be easy but I just can't crack it. Help would be much appreciated!!

Philip Southwell
  • 365
  • 1
  • 6
  • 18

1 Answers1

31

As torazaburo suggests in the comment you can do it in one step with setAttribute() method

document.getElementById("id_price").setAttribute("step","any");
<input type="number" name="price" required="" id="id_price">

OR

First create the attribute and set the value. Then add it to the element..

var attr = document.createAttribute('step');
attr.value="any";
document.getElementById("id_price").setAttributeNode(attr);
<input type="number" name="price" required="" id="id_price">
Sampath Liyanage
  • 4,776
  • 2
  • 28
  • 40