Is there a way to execute the following JavaScript code without using any event and have it run at the start, onLoad of the page?
function calculateDiscount() {
var totalPrice = document.getElementsByClassName("Total")[0].innerHTML;
var discountedPrice = document.getElementsByClassName("DiscPrice")[0].innerHTML;
var discountPercentage = ((totalPrice - discountedPrice) / totalPrice) * 100
document.getElementById("demo").innerHTML = discountPercentage + "% off";
}
<div class="Total">5000</div>
<div class="DiscPrice">3000</div>
<div id="demo"></div>
<button onclick="calculateDiscount()">Click</button>