I would like to have a button styled normally. Then clicked, it will turn green. Then after 3 seconds it will return to its normal style.
I can get the button to change calling to my script with onClick but I get scope errors when I try to work in the function to return it to normal colors.
Javascript:
<script type="text/javascript">
function onClickDelayEvent () {
function newColor(elem) {
elem.style.background = 'green';
elem.style.color = 'white';
}
function normalColor(elem) {
elem.style.background = '';
elem.sytle.color = '';
}
setTimeout(normalColor,3000);
}
</script>
HTML:
<button id="copyButton" onclick="onClickDelayEvent(this)">Copy</button>
The first function (newColor) doesnt fire and I get "elem" undefined on the normalColor function.
If I strip out the extra code and just change the style once it works fine. It's just getting the second part to flip it back that's not working.