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 9053895
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T13:32:29+00:00 2026-06-16T13:32:29+00:00

I’m having a strange situation here.. I have three links which are loading content

  • 0

I’m having a strange situation here.. I have three links which are loading content with ajax. First time when one of these three links is pressed, the content is sliding down but I want that the next li to animate left/right depending on their position in main menu. Right now they are appended to the #content element.

What I want is to give the loaded content from the start a certain index.. as the index which appear in the main menu..

You can see an example at http://www.openminded.ro/

This is the script I’m using right now:

// JavaScript Document
$(document).ready(function(){
    $("#main-menu a").click(function(e){
        e.preventDefault();

        var $a = $(this);
        var $clicked = $a.attr('href').substr(1);

        if($('#logo').hasClass('unmoved')) {
            $('#logo').animate({marginTop:'30px'}, 500, function(){
                $a.removeClass('unmoved').addClass('moved');
            }); 
        }

        $("#main-menu .active").removeClass('active');
        $a.addClass('active');

        if($('#content ul li.' + $clicked).length == 0) {
            $.ajax({
                url: '/resources/ui' + $(this).attr('href') + '.php',
                cache: false
            }).done(function(html) {
                if($('#content ul').html().trim().length == 0) {
                    $("#content ul").html(html).find('li').slideDown(500);
                } else {
                    $("#content ul").css('width',($("#content ul").width() + 900) + 'px');
                    $('#content ul').append(html).find('li.' + $clicked);
                    $a.trigger('click');
                }
            });
        } else {
            $('#content ul').animate({left:-$('#content ul li.' + $clicked).index() * 900 + 'px'}, 500, 'easeInQuart');
        }

    });
});

Right now everything works ok if you press the links in order: About us / Portofolio / Contact but if you start with Portofolio link and then you press About us.. you’ll see that About us is after Portofolio but it must be before it.. I want to set it’s index from the start..

When I load it I want to set About us at index 0, Portofolio 1 and Contact 2 without being dependent if one of these three links has been pressed before

Is there a solution? or I have to do it in hard way?

  • 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-06-16T13:32:30+00:00Added an answer on June 16, 2026 at 1:32 pm

    The problem seems to be with this line:

    $(‘#content ul’).append(html).find(‘li.’ + $clicked);

    It is blindly appending the next chunk of text to the end of whatever was there before, so if you click Contact first it will be to the left of About Us.

    There are other similar problems that come up too, for example try to double click any one of the links, you will probably see the text loaded twice. ( if($('#content ul').html().trim().length == 0) is still true while the first click&ajax request is in progress, so the second click triggers an ajax request and now there is content twice.)

    Idea 1

    One way you can get around all these problems is to forget about using ajax and just preload everything.

    Idea 2

    If you need to use ajax…
    Since you know there are always 3 sections of text I suggest you pre-load all of the <li> tags and then fill them in as each button is clicked. I’ve used the .data() method from jquery to link the button to the correct container.

    your index.php page can start off like:

    <div id="main-menu">
        <a data-container=".about-us" href="/about-us">About us</a>
        <a data-container=".portfolio" href="/portofolio">Portofolio</a>
        <a data-container=".contact" href="/contact">Contact</a>
    </div>
    <div id="content">
        <ul>
            <li class="module about-us"></li>
            <li class="module portfolio"></li>
            <li class="module contact"></li>
        </ul>
    </div>
    
    $('#main-menu a').click(function() {
        var target = $(this).data('container');
        $.ajax({
            // request setup ...
        }).done(function(html) {
    
            $(target, '#content').html(html);
    
            // animate and stuff ...
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I used javascript for loading a picture on my website depending on which small
We're building an app, our first using Rails 3, and we're having to build
I have an autohotkey script which looks up a word in a bilingual dictionary
I have an array which has BIG numbers and small numbers in it. I
I have a text area in my form which accepts all possible characters from
I'm making a simple page using Google Maps API 3. My first. One marker
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I have just tried to save a simple *.rtf file with some websites and

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.