I'm trying to execute foo function when a button is clicked, how can I prevent running scripts onload, sorry for this question, here's an interactive code, my goal is run the function after button click and then display some divs with data. Thanks!
<html>
<head>
<title>Bitcoin Price</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js">
</script>
</head>
<body>
<h1 id="name"></h1>
<p id="cointime"></p>
<div id="dollar"></div>
<div id="gbp"></div>
<div id="euro"></div>
<h6 id="disc" style="width:50%"></h6>
<br>
<button style="width: 200px" onclick="foo()">Load Data</button>
<script>
$.getJSON(
"https://api.coindesk.com/v1/bpi/currentprice.json",
function foo(data)
{
$("#name").append(data.chartName);
$("#cointime").append(data.time.updated);
$("#dollar").append(data.bpi.USD.rate + ' ' + data.bpi.USD.symbol);
$("#gbp").append(data.bpi.GBP.rate + ' ' + data.bpi.GBP.symbol);
$("#euro").append(data.bpi.EUR.rate + ' ' + data.bpi.EUR.symbol);
$("#disc").append(data.disclaimer);
}
)
</script>
</body>
</html>