Trying to make a simple widget. Steps:
1) Load jQuery if not already there 2) Callback a function
<html>
<head>
<script type="text/javascript">
function load(callback){
console.log('load');
if (typeof jQuery !== "function") {
var js = document.createElement("script");
var he = document.getElementsByTagName('head')[0];
js.type = "text/javascript";
js.src = "http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js";
he.appendChild(js);
js.addEventListener("load", function () {
callback();
});
}
else
{
callback();
}
}
load(function(){
chart();
})
function chart(){
$('#chart').html("id : "+Math.random());
}
// alert('This alert breaks!');
</script>
</head>
<body>
<div id="chart"></div>
</body>
</html>
Code works without alert. Cant understand the context issue
Thanks
$('#chart')could be empty object