Reputation: 1
I have an onclick function which I want to be able to press to reset another HTML element (in this case a button id)
function reset(button) {
button.id = "1";
document.getElementById("button.id").innerHTML = button.id;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<!-- close button -->
<button class="btn btn-secondary" onClick="reset();" data-dismiss="modal">
Close
</button>
<!-- close button end -->
<!-- add to cart button -->
<button type="button" onClick="add_price(this); add_image(this);/*reset(this)*/ ;" id="1" class="addtocart btn-primary">
Add to cart
<i class="fas fa-cart-plus ml-2" aria-hidden="true"></i>
</button>
<!-- add to cart button end -->
the /*reset(this)*/
works but not enough since it reset every time I add an item to my shopping cart. I want the id to reset when I exit my modal using to close button (the first button) in this case.
Is there any way to use reset("button.id")
to reset the add to cart button? or something alike?
Upvotes: 0
Views: 392
Reputation: 600
Via JQuery:
$('.btn-secondary').attr('id', 'newID')
Via Javascript
document.getElementByClassName(".btn-secondary").id = "newid";
Upvotes: 1