When it comes to CSS, the :active
selector is considered a CSS pseudo-class and not a DOM property or attribute. This means that there is no direct inline equivalent for it.
However, if you're looking for an alternative solution where the click event can be used, you could implement something like this...
<script>
function toggleBg(element, color) {
if(!color) {
color = element.dataset.normalColor;
} else {
element.dataset.normalColor = element.style.backgroundColor;
}
element.style.backgroundColor = color;
}
</script>
<button onmousedown="toggleBg(this,'red')" onmouseup="toggleBg(this)">RED ON PRESS</button>
It's worth noting that using inline styling or JavaScript isn't generally recommended practice. If possible, consider utilizing CSS instead:
<style>
button:active { background: red; }
</style>
<button>RED WHEN ACTIVE</button>