I have apologized for adding another jQuery question yet but I have beaten my head against this code for a long time I am doing The following code is used on my website: #iframe div to fill with content loaded via $ .get (). ANS works properly (saves unpleasant page leap from irrelevant scrollers and scolisy libraries) but it is not yet able to figure out how to restore page content based on the document. If someone can know why this code is not, or maybe provide some insight whether it is a better way to go about doing it, it would be greatly appreciated.
Thank you before time, Brian
$ (document) .ready (function () {console.log ("execution of embedded jQuery.") If (Document.location.hash.length == 0) {$ ("# home") [0]. Click (); console.log ("clicking the #home link.");} And {$ (document. Location.hash). [0] Click the console.log ("simulate" + Document.location.hash + "click the link.") $ $ ("# Header #nav a"). Function () {if (! $ (This!) .hasClass ("active")} {$ ("#nav a"). RemoveClass ("active"); $ (this) .addClass ("active"); document Location.hash = $ (this) .attr ('href'); switch (document.location. Hash) {case "#home": $ .get ("{text: DocumentRoot} in Dex.html ", function (data) {. $ (" #ifframe ") HTML (data); Console.log (" loaded index.html ");}); break; case" #showcase ": $ .get ( "{Text: documentRoot} showcase.html", function (data) {$ ("# iframe") .html (data); console.log ("loaded showcase.html");}); breakage; case "#out ": $ .get (" {text: documentRoot} about.html ", function (data) {$ (" # iframe "). Html (data); Console.log ("loaded about.html");}); break; Case "#GitB": $ .get ("{text: documentRoot} github.html", function (data) {$ ("# iframe") .html (data); console.log ("loaded github.html") ;}); break; Default: console.log ("no relevant page.") Event.preventDefault (); break; }}}); }); Edit: {text: DocumentRoot} is a tumblr placeholder value that I set:
You are trying to trigger an event before actually setting events as soon as you reorder your code:
$ (Document) .ready (function () {console.log ("executed embedded jam."); $ ("# Header #nav a" .click ("function") (if (! $ (This) .hasClass ( RemoveClass ("active"); $ (this) .addClass ("active"); Document.location.hash = $ (this) .attr ('href' ); Switch (document) .location.hash) {case "#home": $ .get ("{text: documentRoot} index.html", function (data) {$ ("# iframe") .html (data);}); break; Case "#showcase": $ .get ("{text: documentRoot} showcase.html", function (data) {$ ("#iframe"). Html (data);}); break; case "#about": $ .get ("{text: documentRoot} about.html", function (data) {$ ("# iframe") .html (data);}); break; case "#gitb": $ .get ("{ Text: documentRoot} github.html ", function (data) {$ (" # iframe "). Html (data);}); break; Default: event.preventDefault (); break; }}}); If (document.location.hash.length == 0) {$ ("# home"). Trigger ("click"); Console.log ("clicking the #home link."); } And {$ (document.location.hash). Trigger ("click"); Console.log ("simulate" + document.location.hash + "click the link."); }});
No comments:
Post a Comment