I'm trying to call the draw() function when my "#livemap" li element is clicked. The $("#livemap").click() works fine but draw() doesn't.
draw() does work fine when I start the app with the html from livemap.php inside "#content" instead.
This leads me to believe that the document.getElementbyId("a") in draw() doesn't yet know that "a" exists in the HTML... So what do I do about it?
index.html:
<head>
<script>
draw(){
var a = document.getElementById("a");
var b = a.getContext("2d");
var mydiv = document.getElementById("canvascont");
...
}
</script>
<script>
$(document).ready(function(){
$("#livemap").click(function(){
$("#content").load("livemap.php");
draw();
});
...
</script>
</head>
<body>
<!-- Title image and nav bar here-->
...
<li><a id="livemap"><img src ="images/icons/1429420112_icon-map-128.png"/>Map</a>
...
<!-- My main content-->
<div id="container">
<div id="content">
</div>
</div>
</body>
livemap.php:
<div id="canvascont">
<canvas id="a" width="300" height="300"></canvas>
<script>
var a = document.getElementById("a");
var b = a.getContext("2d");
b.fillStyle = "#FF0000";
b.fillRect(2, 2, 10, 10);
</script>
</div>
Any direction on how to fix this would be much appreciated!