Reputation: 10583
The following, very basic script, fails in Chrome and Safari with this error Cannot call method 'appendChild' of null
<!DOCTYPE html>
<html lang="en">
<head>
<script type="text/javascript" src="raphael-min.js">
</script>
<script type="text/javascript">
var paper = Raphael("canvas", 320, 200);
</script>
</head>
<body>
<div id="canvas"></div>
</body>
</html>
I have no idea why - anyone?
Upvotes: 0
Views: 605
Reputation: 22237
Or just call the function after you have defined the div...
<!DOCTYPE html>
<html lang="en">
<head>
<script type="text/javascript" src="raphael-min.js">
</script>
</head>
<body>
<div id="canvas"></div>
<script type="text/javascript">var paper = Raphael("canvas", 320, 200);</script>
</body>
</html>
Upvotes: 1
Reputation: 190907
You should wrap the call when the DOM is ready.
<script type="text/javascript">
// Using JQuery
$(function() {
var paper = Raphael("canvas", 320, 200);
});
</script>
Upvotes: 5