JQuery content displaying only on the first instance

<script>
$(document).ready(function () {

    $('nav>li').hide();
    $('ul').hide();
    $('h2').hide();

          $('a.btnDown').click(function () {
          $('body').css('background', 'tomato');
           $('nav>ul li:hidden').each(function(i) {
           //$('nav>h1').fadeOut(300);
            //$('nav>ul').fadeIn(200);
            $('h1').hide();

            $('nav>ul').delay(i*600).fadeIn(200);
            return false;
        });



    }); //closes a.btnDown

     $('nav>li').click(function () {
        $('nav>ul li:visible').each(function(i) { 

            $('h1').show();
            $('nav>li').hide();
            $('ul li').hide();
            //clearTimeout(fadeTimeout);
            $('nav>li').delay(i*600).fadeOut(200);

        }); //closes visible i

        return false;
        }); //closes a.btnDown

    //all the content elements
    var $suls = $('body>aside>ul');
    var $as = $('a.contentDown').click(function () {
                $('h2').show();
                var $smL = $('h2');
                $smL.animate({
                    left: 300})
            //move nav out of way
                var $nav = $('.navBar');
                $nav.css("left", "auto");
                $nav.animate({
                    right:  300})
            //move menu out of way
                var $menu = $('.menu');
                $nav.css("left", "auto");
                $menu.animate({
                    bottom:  300})
        //hide visible content item
        $suls.filter(':visible').hide();
        //display the content item in the same position as the clicked contentDown
        $suls.eq($as.index(this)).fadeIn(500);
        return false;
    }); //closes contentDown

    $('a.bck').click(function() {

    var $aAside = $('aside');
    $('aside>ul>li:visible').hide();
    $aAside.animate({
        left: 300
    })
    var $smL = $('h2');
        $smL.animate({
            left: -300})
        //move nav back in way
            var $nav = $('.navBar');
            $nav.animate({
            left: 10
            })
    return false;
    }); //closes bck click

}); //closes .ready()
</script>

http://jsfiddle.net/LPDkg/ provides a link to the code I am currently working on. After navigating to menu, then part one, clicking back and attempting to click part one again may result in the content not being displayed. If you have any insights into what might be causing this issue, please feel free to share. Any assistance is appreciated. Thank you.

Answer №1

After clicking the back button, you were hiding the li element. When clicking on the navigation elements, the ul element was being shown. This resulted in the li element being hidden while toggling the visibility of the ul, causing nothing to be displayed.

To resolve this issue, it is recommended to hide the parent ul instead of the li when the back button is clicked.

CHECK OUT THE UPDATED EXAMPLE HERE

Replace this:

$('aside>ul>li:visible').hide();
$aAside.animate({
    left: 300
})

With this:

$('aside>ul:visible').hide();
$aAside.animate({
    left: 300
})

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Encountering an error while trying to add text: SyntaxError - Unexpected token 'for

I'm trying to print out the elements of an array using JavaScript. let listToArray = ["a","b","c"]; $(".tooltip").append(for(let i = 0; i < listToArray.length; i++) {listToArray[i]}); But I keep getting an error that says Uncaught SyntaxError: U ...

Visual Delights on the Menu

I am having trouble adding a "Home" picture to my menu. It keeps showing up as a blank square, even though I have tried using both .png and .jpg formats. Here is the code that I am currently using: <div id='cssmenu'> <link rel= ...

a non-breaking space within a hyperlink

While working on the subnavigation of a website, I encountered an issue with the link Suite «Mont Blanc», which was pulled from the backend. The desired format for this link was:       Suite «Mont Blanc» However, t ...

PHP Simple HTML Dom fails to correctly parse specific links

As I dive into the world of HTML DOM Parsers and how they function, I've encountered a problem. I'm able to parse the root domain and other websites successfully, but for some reason, I can't seem to parse a specific link. Can anyone shed li ...

Is it possible to dynamically group by one column in a dataset without requiring a trigger function?

I've been working on a script that retrieves values from another page and organizes them into a table alphabetically by Name, City, and District. The current script is functioning well, but I now want to enhance it by grouping the values by city as we ...

Seeking help with a Javascript regex inquiry

I am currently utilizing JavaScript regex for the following task: I have gathered the HTML content from a page and stored it within a string. Now, I aim to identify all URLs present on this page. For instance, if the document includes-- <script src = ...

Implementing a way to send nested objects back in response to a jQuery get request

Using jquery.get() to request data from the Spring-Boot backend: var url = "http://localhost:8080/api/v1/get_holdings?userId=1"; $.get(url, function(payload,status) { if (status == "success") { $.each ...

Using AJAX to showcase data from a table in a database using the <select> tag but with an unfinished submit process

I am encountering an issue with my code. When I submit the value in getinv.php, it only returns a partial value. For example, when I click '2016-08-27', it only retrieves '2016'... My question is, how can I ensure that the exact value ...

Knockout Observable Array causing UI to freeze and not refresh properly

I recently started using knockout and am exploring the use of observable arrays to track changes from the UI. The initial data is loaded into the array and I'm attempting to dynamically add new objects to the array from another screen. Although I hav ...

Utilizing Form Validation in Angular 4

In the process of developing a straightforward Angular application that utilizes Twitter Bootstrap and jQuery to showcase employee data. I have hardcoded 4 sets of data which are displayed in a table, as shown in the attached image. The addition of an "Add ...

Align images to the bottom of the gallery only if their heights differ

I'm currently working on an image gallery project and have encountered a problem. When all the image labels are of the same length, they align perfectly. However, if the label is longer than one line, it causes the image to move up instead of creating ...

When trying to apply styles using ng-style attribute with jQuery, Angular does not seem to

Check out this plunker showcasing the issue : http://plnkr.co/edit/1ceWH9o2WNVnUUoWE6Gm Take a look at the code : var app = angular.module('myApp', []); app.controller('myCtrl', function($scope) { console.log('yeah'); ...

Trigger the click event on the ul element instead of the li element using jQuery

Is there a way to make the click event only affect ul tags and not all li elements using jQuery? <!-- HTML --> <ul class="wrap"> <li>test1</li> <li>test2</li> <li>test3</li> </ul> I attemp ...

Traverse through the JSON data until a certain condition is satisfied, then proceed to tally the number

Looking to parse a json file containing user data and points. The goal is to loop through the data until the _id matches the userId, then determine the position of that user in the list based on the number of objects. The json file provided below already ...

Enable the image to extend beyond the boundaries of its containing div

How can I prevent a div from extending its width, allowing an image to be visible outside of it in IE8? Specifically, my div may be 200px wide while the image is 250px wide. ...

Is it possible to load JavaScript code once the entire page has finished loading?

My webpage includes a script loading an external JavaScript file and initiating an Ajax query. However, the browser seems to be waiting for example.com during the initial page load, indicating that this external dependency may be causing a delay. Is there ...

What steps can be taken to implement a code generation feature on our website?

I need to provide the HTML code of my order form to third parties. After they register and pay, they should be able to copy and paste the HTML code from my site onto their own site. The date will then be saved on my site with a reference to the reseller. ...

Using multi-dimensional JSON arrays for posting requests through Ajax

Is it possible to serialize HTML fields in a multi-dimensional array format for AJAX post transmission? I tried using serializeArray but it only formats the first level of the array. The data I need to serialize includes name/value pairs like: name="cus ...

Shared validation between two input fields in Angular 2+

I have a unique task at hand. I am working on creating an input field with shared validation. The goal is to ensure that both fields are technically required, but if a user fills in their email address, then both fields become valid. Similarly, if they ent ...

Unable to access the done property in an AJAX JSON promise

Trying to dive into the world of JavaScript promises. My goal is to create a button that triggers a function displaying the result of a promise from another function. So far, I've been following tutorials and here's where I'm at: function my ...