Steps for displaying a division on clicking a hyperlink

I am currently working on my main menu layout in HTML, and here is the code snippet:


        <div id="main-container">
            <div id="main-wrapper">
                <div id="logo">
                    <h1 id="title">portfolio</h1>

                    <h2 id="ready">ready</h2>
                </div>

                <div id="selection">
                    <ul>
                        <li><a href="#" id="about">about</a></li>
                        <li><a href="#" id="resume">resume</a></li>
                        <li><a href="#" id="portfolio">portfolio</a></li>
                        <li><a href="#" id="contact">contact</a></li>
                    </ul>
                </div>
            </div>
        </div>
    

I have a vision of adding some cool animations to my website. For instance, when the "about" link is clicked, I want a specific div to be displayed. Here is the div I'm referring to:


        <div id="secondary-container">
            <div id="about-wrapper">
                <div id="header">
                    <h1 id="about-heading">about</h1>
                </div>

                <div id="information">
                    <h2 id="introduction">introduction:</h2>
                    <p id="paragraph">hello! welcome to my website!</p>
                </div>

                <div id="content">
                    <h2 id="my-information">my information:</h2>
                    <ul>
                        <li>name: <span>danny moon</span></li>
                        <li>age: <span>21</span></li>
                        <li>sex: <span>male</span></li>
                        <li>location: <span>new jersey</span></li>
                    </ul>
                </div>

                <div id="feature">
                    <h2 id="my-skills">my skills: </h2>
                    <ul>
                        <li>html: <span>50%</span></li>
                        <li>css: <span>50%</span></li>
                        <li>javascript: <span>30%</span></li>
                        <li>python: <span>60%</span></li>
                    </ul>
                </div>
            </div>
        </div>
    

Currently, my jQuery code is quite basic:

$(document).ready(function(){
        $('#about').click(function(){
            $('#secondary-container').show();
        });
    });

However, upon clicking the "about" link, nothing seems to happen. Any suggestions or advice would be greatly appreciated. If you require access to my full HTML, CSS, jQuery, or JavaScript folders, you can find them in this Dropbox link:

Thank you for your help.

Answer №1

Have you checked the files you shared for any small syntax errors? I noticed that there are missing closing brackets '>' at the end of the script tags that should be present. Here's how it should appear:

<script type="text/javascript" src="../jquery/jquery.js"></script>
<script type="text/javascript" src="../jquery/jquery-ui.js"></script>
<script type="text/javascript" src="../js/showhide.js"></script>

Answer №2

When using the dummy href="#" in your link, it may still behave like a regular link by adding the "#" anchor to your URL. To prevent this default link behavior, you can use event.preventDefault():

$(document).ready(function(){
    $('#about').click(function(event){
        event.preventDefault();
        $('#secondary-container').show();
    });
});

Make sure to include the event parameter in your click event function.

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

Center an image vertically and horizontally within a div element inside a container, even if the image sizes and aspect ratio differ, while also including padding

I am looking to vertically align images with varying ratios, where the image may be larger or smaller than the content and also include padding; I have tried different solutions found here, but none seem to cover all my requirements; I specifically need i ...

A guide to retrieve data attributes in Vue.js

When my button is clicked, a modal pops up with data passed through data attributes. The button code looks like this: <button class="edit-modal btn btn-info" data-toggle="modal" data-target="#editModal" :data-id=item.id ...

Positioning the footer to sit at the bottom of my webpage, leaving a pleasing margin at the top

One technique I frequently use to ensure my footer stays at the bottom of my page is by utilizing an empty div. Here's how the code looks: <body> <div id="canevas"> <article>My website's content</article> ...

What is the best way to organize React components/modules in order to effectively separate the UI?

Currently, I have developed three key components for a dashboard UI project in React. These components include a sidebar, top navigation bar, and a content container. As someone who is new to React after working with Angular, I am now seeking advice on how ...

Navigating through the Roots in ICanHaz.js / Mustache

I'm encountering a problem with iterating using ICanHaz.js / Mustache. My goal is to iterate over the roots of a JSON structure and extract a specific parameter. This is the JSON I'm working with: { "1": { "param1": "true", "param2": "fa ...

Tips for showing a single table with buttons on display

I am using R markdown and have included multiple tables with buttons, but when I open the file, all tables are displayed at once. How can I ensure only one table is shown upon opening the file? https://i.sstatic.net/NFidf.png <script type="text/ja ...

HTML: Learn how to concatenate the href attribute of an anchor tag instead of replacing it

I am currently on the page www.myUniqueWebsite.com/sign-up?type=explore In the navigation menu, there is a link to switch languages. <a href="?lang=es">Spanish</a> When I click on this link, it redirects me to www.myUniqueWebsite.com/ ...

What is the most effective method to patiently anticipate a specific duration for a function's output?

I am faced with a situation where I have two functions at hand. One function performs complex logic, while the other wraps this function to provide either the result of computation or an error message after a specified amount of time t. Consider the follo ...

What is the best way to initiate WebXR from an iframe in a Next.js environment?

I am currently working on a Next.js app: https://codesandbox.io/s/next-js-forked-6fgnr7?file=/index.tsx I have implemented the functionality for it to open WebXR on Android Chrome when clicking on the AR button located at the bottom left ("in AR betracht ...

Upon selecting multiple checkboxes, corresponding form fields will be displayed based on shared attributes

When multiple checkboxes are selected by the user, corresponding form fields should appear based on the checkboxes. For example, if both flight and hotel checkboxes are checked, then the full name and last name fields should be displayed while other fields ...

Form a collection using multiple elements

I'm attempting to combine multiple arrays into a single array. For instance : array1= ['Joe','James','Carl','Angel','Jimmy',]; array2= ['22','11','29','43',&apo ...

Grouping and retrieving values from an array of JavaScript objects

I am looking to implement a groupBy function on the object array below based on the deptId. I want to then render this data on a web page using AngularJS as shown: Sample Object Array: var arr = [ {deptId: '12345', deptName: 'Marketin ...

Incorporating an image into a list of checkboxes post-connection

Looking for a way to populate a checkbox list through datasource/databind and then integrate an image with each checkbox? I can do both separately but struggling to combine them successfully. My task is to create a checkbox list of students for teachers t ...

Is it possible to access a comprehensive list of all the elements that are currently available?

Is there a way to retrieve all HTML tag names that are supported by the browser for my web application? I want it to be displayed like this: console.log(getAllElements()) //[a, abbr, acronym, address, applet, area, base, ...] ...

Updating multiple documents in Mongoose that have a specific element in an array

I have structured a Mongoose schema like this: const mongoose = require('mongoose'); const ItemSchema = mongoose.Schema({ id: { type: String, required: true, }, items: { type: Array, required: true, }, date: { type: ...

Loading React Components dynamically depending on user input

Looking to dynamically render different Components based on checkbox selections without unnecessary component imports. Using an Array with Component names (using numbers for example) to import each component based on the array values. Considered the foll ...

The step-by-step guide for replacing the extJs Controller component

I have developed a versatile component that is being utilized across different products. In this case, I have a generic window and window controller which I am customizing to fit our specific product requirements. This is my generic window: Ext.define(&a ...

Confusing postback phenomena in ASP.NET web forms

I have developed a small script that successfully maintains the focused element during an async postback. However, I encountered an issue when tabbing through controls generated inside an asp:Repeater, where a full postback is unexpectedly triggered. Below ...

The Fullpage.js embedded in an iframe is experiencing difficulty scrolling on iOS mobile devices

Trying to use Fullpage.js for a website with unique sections on different domains using full-screen iframes. However, encountering issues with scrolling on IOS mobile devices. The first solution rendered the page completely unscrollable: <iframe src=" ...

Which element can be slotted?

Is it possible to use a tr (table row) for a named slot? What is the outcome when a tr is used as a slot's fallback content? For example: <x-table> <tr slot="x-row"> <td>data</td> <td>data</td> ...