Programmer
Programmer

Reputation: 6753

How to ensure page loaded before calling javascript file

I have a canvas element in my page. I need that to finish loading before calling javascript file .any suggestions

Upvotes: 0

Views: 308

Answers (3)

bilash.saha
bilash.saha

Reputation: 7316

The old and best way is to place JS code towards the end of the page, just inside the closing body tag. Thus you can assure that the DOM is ready.

Upvotes: 1

Niet the Dark Absol
Niet the Dark Absol

Reputation: 324750

Put the <script> tag somewhere after the <canvas> tag.

Or use jQuery (ugh) and its document ready thing, whatever...

Upvotes: 2

Dan Shookowsky
Dan Shookowsky

Reputation: 221

You can use jQuery and put your code inside a function

$(document).ready(function () {
    // put code here
});

Upvotes: 2

Related Questions