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

  • SEARCH
  • Home
  • 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 6661657
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:18:24+00:00 2026-05-26T02:18:24+00:00

I want to separate these functions. They should both work separately on click events:

  • 0

I want to separate these functions. They should both work separately on click events:

FIRST FUNCTION

 $("ul.nav li").delegate("a", "click", function() {
        window.location.hash = $(this).attr("href");
        return false;
    });

    $(window).bind('hashchange', function(){

newHash = window.location.hash.substring(1);

        if (newHash) {
           ACTION A
      });
$(window).trigger('hashchange');
 });

SECOND FUNCTION

 $("ul.subnav li").delegate("a", "click", function() {
        window.location.hash = $(this).attr("href");
        return false;
    });

    $(window).bind('hashchange', function(){

newHash = window.location.hash.substring(1);

        if (newHash) {
           ACTION B
      });
$(window).trigger('hashchange');
 });

This is what happend in ACTION A:

 $mainContent
                .find(".maincontent")
                .fadeOut(200, function() {
                    $mainContent.hide().load(newHash + " .maincontent", function() {
                        $mainContent.fadeIn(200, function() {
                            $pageWrap.animate({
                                height: baseHeight + $mainContent.height() + "px"
                            });
                        });
                        $(".nav a").removeClass("active");
                        $(".nav a[href="+newHash+"]").addClass("active");
                    });
                });

The Problem is that if I click the Link of the Second function always the the first function fires.

Details of what I’m trying to do:

First, I build my site on .php to serve poeple without JavaScript. Now I want to load the “maincontent” dynamically. So I found this script I’m using:

http://css-tricks.com/6336-dynamic-page-replacing-content/

It does do a great job if you only want to load “maincontents”.

But my site has sub-navigation on some pages where I want to load the sub-content. In .php these sites use includes. So I get my content by: href=”page2.php?page=sub1″

So, when I click on the sub-links now they load also dynamically but the script also on the whole maincontent loading area. So it doesn’t really load content by .load() but the sub-content of the includes do appear.

So what I thought was just to separate this function. The first to simply load the maincontents and a second one for the sub-navigation to refresh only the sub-content area. I don’t even understand how this script loads the include content dynamically since the link is the straight page2.php?page=sub1 link. All dynamic loaded content usually looks like “#index”, without the ending “.php”.

Some quick history:

I’m trying to get the best page structure. Deliver .php for non JavaScript user and then put some dynamic loading stuff over it. Always with the goal to keep the browser navigation and the browser links (for sharing) for each page in tact.

I’m not an jQuery expert. All I have learned so far was by trial and error and some logical thinking. But of course, I have a lack of fundamental knowledge in JavaScript.

So my “logical” question:

How can I tell the “nav” links to perform only their “$(window).bind”-Event and to tell the “subnav” links only to perfom their “$(window).bin”-event.

Is this the right thinking?

Since I’ve already been trying to solve it for nearly the last 18h, I’ll appreciate any kind of help.

Thank you.

IMPORTANT:

With the first function I not just only load the maincontent but also I’m changing a div on the page with every link. So for any solution that might want to put it together in one, it won’t work, cause they should do different things on different areas on the page. That’s why I really need to call on the window.bind with each nav/subnav click.

Can anyone show me how?

  • 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. Editorial Team
    Editorial Team
    2026-05-26T02:18:24+00:00Added an answer on May 26, 2026 at 2:18 am

    Here’s by the way the solution I came to:

    After understanding that the haschange-event doesn’t have to do anything with it (as long as you don’t want to make the subcontent bookmarkable too) I just added a new load function for the subcontent:

    $(function(){
    
                $("ul.linkbox li a").live('click', function (e) {
                newLink = $(this).attr("href");
                e.preventDefault();
    
                    $(".textbox").find(".subcontent").fadeTo(200,0, function() {
    
                        $(".textbox").load(newLink +  " .subcontent" , function() {
    
                            $(".subcontent").fadeTo(200,1, function() {
    
    
    
                            }); 
                        }); 
    
                    $("#wrapper").css("height","auto");
                    $("ul.linkbox li a").removeClass("activesub");
                    $("ul.linkbox li a[href='"+newLink+"']").addClass("activesub");
    
                    });
    
            });
    
    }); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In the following code I want to reduce these 5 functions down to 3.
I have the simplest code that I want to separate in three files: Header
I know that with a large site you would want to separate footers, menus,
I have a web application that is becoming rather large. I want to separate
I want to create separate folders for my layouts, like this in my resource
I want to create 2 separate pickers in the same view using the same
I want to create a separate thread that runs its own window. Frankly, the
I want to keep SSH debug info separate (and logged) from other input. However,
I want to use CSS sprites on a web site instead of separate image
I want to know how I can run a method in a separate thread?

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.