When a block is clicked, jQuery will reveal that block while hiding the others sequentially, starting with the second block, then the third, and finally the fourth

Creating a navigation menu with 4 blocks can be a bit tricky, especially when trying to show one block at a time upon click. Here is my code attempt, but unfortunately it's not working as expected. I would greatly appreciate any help or suggestions on how to fix it. Thank you! You can view the code below or by visiting this link: http://jsfiddle.net/9afaF/

<div class="games_content">

            <script>
                $(function() {
                    $("#block_2 div,#block_3 div,#block_4 div").hide();

                    $("#block_1 div").click(function(){
                        $("#block_2 div,#block_3 div,#block_4 div").hide();
                        $("#block_2 div."+$(this).attr('id')).show("fast");

                        $("#block_2 div").click(function(){
                            $("#block_3 div,#block_4 div").hide();
                            $("#block_3 div."+$(this).attr('id')).show("fast");

                            $("#block_3 div").click(function(){
                                $("#block_4 div").hide();
                                $("#block_4 div."+$(this).attr('id')).show("fast");
                            })
                        });
                    });
                });
            </script>
            <div style="float:left;width:237px;height:420px;background: rgba(255, 0, 0, .5);margin-right:15px;" id="block_1">
                <div id="category1">Category 1</div>
                <div id="category2">Category 2</div>
                <div id="category3">Category 3</div>
                <div id="category4">Category 4</div>
                <div id="category5">Category 5</div>
            </div>

            <div style="float:left;width:164px;height:500px;background: rgba(255, 0, 0, .5);margin-right:2px;margin-top:10px;margin-left:4px;" id="block_2">
                <div class="category1" id="subcat1">Sub Category 1</div>
                <div class="category1" id="subcat2">Sub Category 2</div>
                <div class="category1" id="subcat3">Sub Category 3</div>
                <div class="category2" id="subcat4">Sub Category 4</div>
                <div class="category2" id="subcat5">Sub Category 5</div>
                <div class="category3" id="subcat6">Sub Category 6</div>
                <div class="category3" id="subcat7">Sub Category 7</div>
                <div class="category4" id="subcat8">Sub Category 8</div>
                <div class="category4" id="subcat9">Sub Category 9</div>
                <div class="category5" id="subcat10">Sub Category 10</div>
                <div class="category5" id="subcat11">Sub Category 11</div>
            </div>

            <div style="float:left;width:160px;height:500px;background: rgba(255, 0, 0, .5);margin-right:2px;margin-top:10px;" id="block_3">
                <div class="subcat1" id="game1">Sub Sub Categoey 1</div>
                <div class="subcat1" id="game2">Sub Sub Categoey 2</div>
                <div class="subcat2" id="game3">Sub Sub Categoey 3</div>
                <div class="subcat2" id="game4">Sub Sub Categoey 4</div>
                <div class="subcat3" id="game5">Sub Sub Categoey 5</div>
                <div class="subcat4" id="game6">Sub Sub Categoey 6</div>
            </div>

            <div style="float:left;width:240px;height:400px;background: rgba(255, 0, 0, .5);margin-left:17px;" id="block_4">
                <div class="game1">Game1</div>
                <div class="game2">Game2</div>
                <div class="game3">Game3</div>
                <div class="game4">Game4</div>
            </div>

Answer №1

It appears that the jquery library is missing from your fiddle.

To see it in action, click on this FIDDLE

$(function() {
    $("#block_2 div,#block_3 div,#block_4 div").hide();

    $("#block_1 div").click(function(){
        $("#block_2 div,#block_3 div,#block_4 div").hide();
        $("#block_2 div."+$(this).attr('id')).show("fast");

        $("#block_2 div").click(function(){
            $("#block_3 div,#block_4 div").hide();
            $("#block_3 div."+$(this).attr('id')).show("fast");

            $("#block_3 div").click(function(){
                $("#block_4 div").hide();
                $("#block_4 div."+$(this).attr('id')).show("fast");
            })
        });
    });
});

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

What steps do I need to take to adjust this function based on the timezone?

Is there a way to retrieve the current time based on a specific timezone of my choice? let getCurrentTime = () => { var today = new Date(); var hh = String(today.getHours()) var mm = String(today.getMinutes()) //January is 0! var ss = ...

Can you explain the significance of the regular expression pattern /(?:^|:|,)(?:s*[)+/g in Javascript?

When it comes to Jquery, the regexp pattern is defined as follows: var rvalidbraces = /(?:^|:|,)(?:\s*\[)+/g; This particular pattern is designed to match strings such as "abc,[" and "abc:[", while excluding instances like "abc^[". But what doe ...

Navigating through a diagonal path

Struggling to craft a diagonal navigation system similar to the images below. Despite its seemingly simplicity, I'm stuck investing too much time in figuring it out. My goal is for the menu container to smoothly reveal from right to left when clicking ...

What is the process for displaying user input on the console?

How can I ensure that the server is receiving user input? What steps should I take to print this input to the console? Currently, the console.log statement only displays "About to create new room", but I require the user input as well. Client-Side: // C ...

Checking React props using Jest and Enzyme - A simple guide

Trying to understand React testing, I came across two files: Button.js and Button.test.js The code below contains the question along with comments: // Button.js import React from 'react'; import { string, bool, func } from 'prop-types&apos ...

Utilizing Page Methods

I have encountered an issue while using an ajax callback for a void method. When I try to call another method within the calling method, I get an error. Any assistance with resolving this problem would be greatly appreciated. Here is the code snippet: ...

What is the best way to stop the content in :after from wrapping onto the following line?

How can I add a divider "/" after each li element in my Bootstrap-based menu without it wrapping to the next line? The code I am using can be found here: http://jsfiddle.net/zBxAB/1/ I have tried using inline-block to prevent the slash from wrapping, but ...

The emission from Socket.io is originating from the recipient's browser without being transmitted to the sender's browser

Hey there, I'm fairly new to socket.io and not completely sure if what I'm doing is the standard way, but everything seems to be working fine so I guess it's okay. I've been working on a chat application where messages are stored in a d ...

Is it possible to utilize Angular's $http.get method with a dynamic route

I recently started working with Angular and I'm trying to figure out how to retrieve data from a REST API using a scope variable to determine the URI for the GET request. Imagine that I have an array of numbers being generated by a service in my app ...

Dynamic TextField sizing

I am currently facing an issue while displaying data on a webpage using TextField component from @material-ui. Each record of data has varying lengths, making most values appear unattractive (occupying only 10% of the textfield width). Even though I am ut ...

Unknown passport authentication method

I'm currently delving into a tutorial on building an authentication system using passport in Nodejs. The guide can be found here. My focus right now is on getting the signup form to function properly, but it keeps throwing this error: Error: Unknown ...

Tips for integrating an HTML template into a React project

I'm finding it challenging to integrate an HTML template into React. The template I am using is for an admin dashboard with multiple pages. I have successfully copied and pasted the HTML code into JSX files and fixed any syntax issues. Here's wh ...

Is it possible to load multiple angular applications within a master angular shell application?

I am searching for a method to integrate multiple Angular applications into a single shell Angular application. The concept involves having different teams develop separate Angular apps that can be loaded within a main shell app visible to end users. Thi ...

Manipulate the way in which AngularJS transforms dates into JSON strings

I am working with an object that contains a JavaScript date, structured like this: var obj = { startTime: new Date() .... } When AngularJS converts the object to JSON (for instance, for transmission via $http), it transforms the date into a string as ...

Tips for passing parameters in a BootstrapDialog.show({ }) function popup

I am trying to display a popup using BootstrapDialog and pass a parameter with it. I have used the data attribute in my code snippet as shown below: BootstrapDialog.show({ closable: false, title: "This is my custom popup", message: $(' ...

I keep encountering the issue where I receive the message "Unable to access property 'innerText' of an undefined element" when running the Array forEach function. This problem seems to be happening within the HTMLInputElement section of the code

I am facing an issue where the error occurs because "cardTxt" is not recognized as a string. I verified this using typeof syntax, but I'm unable to understand why it can't be a string. This code snippet includes the use of bootstrap for styling. ...

What is the proper way to connect an external Javascript file to an html document within a Play Framework project?

Below is the content of my scala.html file: @() <!DOCTYPE html> <html> <head> <title> Spin To Win </title> <link rel="stylesheet" media="screen" href="@routes.Assets.versioned("stylesheets/styles.css")" ...

Connecting Datatables to dynamically loaded tables using Ajax

Currently, I am utilizing bootstrap nav-tabs to load tabs content via ajax. The challenge I am facing involves having two tables within the ajax loaded content that need to be incorporated with the datatable jQuery plugin. I understand that using the &apos ...

Can the default DOM structure of a Jquery Data Table be customized to fit specific needs?

I have incorporated a Jquery Data Table Plugin that can be found at http://datatables.net/api. This plugin comes with its own search box, which is automatically added to the page when enabled. The search box is nested within its own div structure like this ...

What is the best way to save a parsed JSON value to a variable in Express?

I am currently utilizing the body-parser module to parse incoming JSON objects within a POST request. My goal is to extract and store a specific value from the JSON data into a variable for later database insertion. Below is a fragment of the code: var h ...