-2

I want to change and revert element id while onclick button.

Html : <p id="tprice">Price Total: $<span id="order_total">0</span></p>

Want to change and revert this id="order_total" to this id="rsorder_total" after click on this button:-

<input type="button" value="USD" id="myButton"></input>
  • 5
    What is the reason for this? If it is to change the style, just add/remove css classes. – Get Off My Lawn Aug 07 '19 at 16:36
  • 1
    Take a look at the answers to [this question](https://stackoverflow.com/q/1650299/). But as Get Off My Lawn said, it sounds like you should be using classes rather than IDs. – jirassimok Aug 07 '19 at 16:37
  • 2
    usually you don't change elements `id`. If you need to change it because the need to keep track of some attribute or order, then I suggest to use `data-...` attribute, or if it's to change element's style, then use CSS classes as stated in the first comment – Calvin Nunes Aug 07 '19 at 16:38
  • What he said 100% – Chris W. Aug 07 '19 at 16:59

1 Answers1

-2

you can access your button by the dom and then you can change it.

easily you can add an event listener on the button, then use the dom also. document.getElementById("myButton").addEventListener("click", function(){ document.getElementById("order_total").id = "rsorder_total"; });