Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 156235
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T10:17:45+00:00 2026-05-11T10:17:45+00:00

My problem is a little bit complex. I have the following code: $(document).ready(function() {

  • 0

My problem is a little bit complex.

I have the following code:

$(document).ready(function() {      var hash = window.location.hash.substr(1);     var href = $('#nav li a').each(function(){         var href = $(this).attr('href');         if(hash==href.substr(0,href.length-5)){             var toLoad = hash+'.html #content';             $('#content').load(toLoad)         }                                                });      $('#nav li a').click(function(){          var toLoad = $(this).attr('href')+' #content';         $('#content').hide('fast',loadContent);         $('#load').remove();         $('#wrapper').append('<span id='load'>LOADING...</span>');         $('#load').fadeIn('normal');         window.location.hash = $(this).attr('href').substr(0,$(this).attr('href').length-5);         function loadContent() {             $('#content').load(toLoad,'',showNewContent())         }         function showNewContent() {             $('#content').show('normal',hideLoader());         }         function hideLoader() {             $('#load').fadeOut('normal');         }         return false;      });  }); 

Okay, first it’s not me who coded it, so I really don’t understand what it does and also I tried to change it but i didn’t succeed. The code will select a ‘nav li’ link and display the page in an AJAX way, this mean without reloading it. It does this correctly 🙂 Now, all I want to do it to add a fancybox to register users. To do that I should add the following code.

$('a#reg').fancybox({     'hideOnContentClick': false }); 

now I just put the code in $document.readyfunction and the fancy box works as it should, also the nav li links works well. So where’s the problem? when I click a ‘nav li’ link and it load the content and then click again on the the home link, (I return to the first page), the fancy box no longer works. I know it’s very sensitive so may be you have bad-understood it, so let me explain it in another way. I have both the selector of the ‘nav li’ and the selector of the fancy box link, what is the best method to make them works together??

Also can someone explain to me what the code does as well.
Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T10:17:45+00:00Added an answer on May 11, 2026 at 10:17 am

    Ok… Here is what the code does :

        var hash = window.location.hash.substr(1);     var href = $('#nav li a').each(function(){         var href = $(this).attr('href');         if(hash==href.substr(0,href.length-5)){                 var toLoad = hash+'.html #content';                 $('#content').load(toLoad)         }                                                                                            }); 

    This first part will get the hash of current page, check that one of the ‘nav li’ links ends with this hash (5 chars expected) and if it’s the case, will load the #content element of page hash + '.html' in the #content element of current page (I suppose it’s a div).

    Imagine you load the url ‘http://…/page1.html#page2‘. Page1 will be loaded and then, #content of page2.html will be loaded by an ajax call in #content of page1.

        $('#nav li a').click(function(){          var toLoad = $(this).attr('href')+' #content';         $('#content').hide('fast',loadContent);         $('#load').remove();         $('#wrapper').append('<span id='load'>LOADING...</span>');         $('#load').fadeIn('normal');         window.location.hash = $(this).attr('href').substr(0,$(this).attr('href').length-5);         function loadContent() {                 $('#content').load(toLoad,'',showNewContent())         }         function showNewContent() {                 $('#content').show('normal',hideLoader());         }         function hideLoader() {                 $('#load').fadeOut('normal');         }         return false;      }); 

    This will add the following behaviour to ‘nav li’ links : when clicked, show a ‘loading message’ and load the #content of target page in #content element of current page.

    I don’t have any idea why this script, despite being terrible, would cause your fancybox not to show. My guess is that the ‘nav li’ links will load the content with an ajax call and this will not affect your fancybox, which is already loaded, but when you click the home link, the page is completely reloaded and the fancybox code is not executed, for a reason. You can check that by adding a simple alert :

    alert('initializing fancybox'); $('a#reg').fancybox({     'hideOnContentClick': false }); 

    If the full page is reloaded when you click the home link, and this alert does not popup, you found the cause of your problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 120k
  • Answers 120k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer It is better to download it and link to the… May 12, 2026 at 12:03 am
  • Editorial Team
    Editorial Team added an answer The error code was a feature used when there was… May 12, 2026 at 12:03 am
  • Editorial Team
    Editorial Team added an answer You didn't post code on how you're accessing the data… May 12, 2026 at 12:03 am

Related Questions

I'm getting in to a situation where I have several interacting widgets (on a
OK, having tried my first TDD attempt, it's time to reflect a little and
My problem is a little bit complicate. (I use PHP) I have two arrays,
My problem is a little bit hard but simple. I have (or there is)

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.