I want to change the innerText of elements on my HTML after loading them.
<strong class="price" onclick="toPriceFormat(this)">2000</strong>
<strong class="price" onclick="toPriceFormat(this)">3000</strong>
<strong class="price" onclick="toPriceFormat(this)">1000</strong>
and I use this javascript function:
<script>
function toPriceFormat(x) {
let initText = parseInt(x.innerText);
newTextFormat = new Intl.NumberFormat().format(initText);
x.innerText = newTextFormat;
}
</script>
This onclick
works but doesn't work onload
event, for example I can't change my HTML to:
<strong class="price" onload="toPriceFormat(this)">2000</strong>
<strong class="price" onload="toPriceFormat(this)">3000</strong>
<strong class="price" onload="toPriceFormat(this)">1000</strong>
I want to know what's the different in functionality of onclick
and onload