Calling external jQuery functions w/o document.ready(); -
kinda new jquery , looking on how keep script in 1 external file , not have nested in document.ready();. i'm hoping able call functions specific pages , have rest handle ready();. i'm not 100% sure best practice call function page either :/ thanks.
there nothing wrong having multiple document.readys
i add unique id each page, , have javascript check id exists before executing. can create simple wrapper function check , waits document.ready:
var pageready = function (id, callback) { $(function () { if ($(id).length) { callback(); } }); };
then, similar document.ready, can have:
pageready("#home-page", function () { // code run home page here }); pageready("#search-page", function () { // code run search page here });
just remember add ids...
<body id="home-page">
Comments
Post a Comment