I have a button that changes an element's style. Can I have this button auto-reset the CSS changed, back to default? Here is the code:
<div ><img id="coin1" src="/wp-content/uploads/2022/10/coin.png" alt="box" width="40" height="40">
<a onclick="tosscoin()"><img src="/wp-content/uploads/2022/10/coinbox.png" alt="box" width="40" height="40"></a>
<audio id="audio" src="/wp-content/uploads/2022/10/coinsound.mp3"></audio>
<script>
function tosscoin() {
document.getElementById("coin1").style.transform = "translatey(-70px)";
var audio = document.getElementById("audio");
audio.play();
}
</script>
</div>
CodePudding user response:
This should remove all styles from that element:
document.getElementById("coin1").style.cssText = null
CodePudding user response:
To remove css styles from an element using js Removes all styles.
document.getElementwithSomeMethod.style=null
document.getElementwithSomeMethod.style.cssText=null
Remove a single style
document.getElementBySomeMethod.style.removeProperty(propertyName)