domReady()

Run the specified function when the DOM is ready for manipulation.

Syntax domReady(function)

Return Type undefined

Description

Run the specified function when the DOM is ready for manipulation. If your script is placed above the HTML canvas element in your code, you need to wrap your script with this function. If you don't do that, oCanvas won't find the canvas element you pass in to the oCanvas.create() method, since it hasn't been loaded yet. Best practice though is to always place all your JavaScript code in the bottom of the page, right before the closing tag for body, because scripts otherwise block the loading of the rest of the page while the script is loading.

Arguments

function : Function
The function that will be called when the DOM is ready. Place all of your code inside this function.

Return Value

undefined. Doesn't return anything.

Examples

Example 1

We wrap all our code with this function call, to delay the execution of oCanvas.create() until the DOM is ready and the canvas element can be found.

View Example
Code
oCanvas.domReady(function () {
	var canvas = oCanvas.create({
		canvas: "#canvas",
		background: "#0cc"
	});
});
Output