Categories
JavaScript Tips & Tutorials

A slightly better approach than <body onload="…">

A tiny little quick tip for javascript beginners.

While you still can execute javascript code upon page loading completion with:

<body onload="jsFunc();">

You can just attach or define an onload event to body in the normal code flow:

window.onload = function() {
	jsFunc();
}

By Yang Yang

Hello, I'm Yang. I build online businesses that please people. Want to join in and post some useful articles on Kavoir.com? Shoot me a message.