Switch up the text when the menu is clicked

Is there a way to create a dynamic menu system that changes text depending on which menu is clicked, without having to create multiple nearly identical pages? I've searched online but haven't found a solution yet. Using the visibility tag in CSS hides the text but leaves empty spaces, which isn't ideal for displaying a lot of content. What would be the best approach to achieve this?

HTML:

    <html>
  <head>
    <script src="http://thecodeplayer.com/uploads/js/prefixfree-1.0.7.js" type="text/javascript" type="text/javascript"></script>
    <script src="http://thecodeplayer.com/uploads/js/jquery-1.7.1.min.js" type="text/javascript"></script>
    <script src="js/menu.js" type="text/javascript"></script>
    <link rel="stylesheet" type="text/css" href="css/menu.css">

  </head>
  <body>

    <div id="accordian">
        <ul>
            <li class="active">
                <h3><span class="icon-dashboard"></span>Menu 1</h3>
                <ul>
                    <li><a href="#">Submenu 1</a></li>
                    <li><a href="#">Submenu 2</a></li>
                    <li><a href="#">Submenu 3</a></li>
                </ul>
            </li>
            <li>
                <h3><span class="icon-tasks"></span>Menu 2</h3>
                <ul>
                    <li><a href="#">Submenu 4</a></li>
                    <li><a href="#">Submenu 5</a></li>
                    <li><a href="#">Submenu 6</a></li>
                </ul>
            </li>
            <li>
                <h3><span class="icon-calendar"></span>Menu 3</h3>
                <ul>
                    <li><a href="#">Submenu 7</a></li>
                    <li><a href="#">Submenu 8</a></li>
                    <li><a href="#">Submenu 9</a></li>
                </ul>
            </li>
      </ul>
    </div>
  </body>
</html>

CSS:

 @import url(http://fonts.googleapis.com/css?family=Nunito);
* {margin: 0; padding: 0;}

body {
    background: #4EB889;
    font-family: Nunito, arial, verdana;
}
#accordian {
    background: #004050;
    width: 250px;
    margin: 100px auto 0 auto;
    color: white;
    box-shadow:
        0 5px 15px 1px rgba(0, 0, 0, 0.6),
        0 0 200px 1px rgba(255, 255, 255, 0.5);
}
#accordian h3 {
    font-size: 12px;
    line-height: 34px;
    padding: 0 10px;
    cursor: pointer;
    background: #003040;
    background: linear-gradient(#003040, #002535);
}
#accordian h3:hover {
    text-shadow: 0 0 1px rgba(255, 255, 255, 0.7);
}
#accordian h3 span {
    font-size: 16px;
    margin-right: 10px;
}
#accordian li {
    list-style-type: none;
}
#accordian ul ul li a {
    color: white;
    text-decoration: none;
    font-size: 11px;
    line-height: 27px;
    display: block;
    padding: 0 15px;
    transition: all 0.15s;
}
#accordian ul ul li a:hover {
    background: #003545;
    border-left: 5px solid lightgreen;
}
#accordian ul ul {
    display: none;
}
#accordian li.active ul {
    display: block;
}

jQuery:

$(document).ready(function(){
    $("#accordian h3").click(function(){
    if(!$(this).next().is(":visible")) {
        $(this).next().slideDown();
        } else {
            $(this).next().slideUp();
        }
    })
})

Answer №1

To modify the appearance, you can utilize the hide() and show() functions without adjusting the css stylesheet.

Here is a demonstration

Answer №2

Appreciate all the assistance. Managed to resolve the issue by implementing an opentab feature for the navigation links and toggling the display accordingly. It appears that one user had recommended this solution earlier, although their response has been removed.

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

JQUERY confirm dialog causing AJAX malfunction

I am encountering an issue where I am trying to execute an ajax function only after the user confirms a dialogue using JQUERY confirm. Strangely, when I include the confirmation step, my code throws an error and does not function properly. It's worth ...

The feature of window.open and pop-up blocker integrated into the $.ajax().done() function is

When my jQuery ajax call is completed, I need to open a URL in a new tab. Here's the function I created for this purpose: var openNewTab = function() { window.open('/UrlToOpen', '_blank'); win.focus(); } If I directly cal ...

Tips for invoking a JavaScript function within an iframe

I'm looking to add an iframe to my HTML document, but I also need to pass a variable from a JavaScript function that is located on the same page (which retrieves cookie values). <script type=text/JavaScript> var generateLinkerUrl = function(url ...

Locate a particular text and enhance it with bold styling by utilizing JavaScript or jQuery

I am searching for a specific string within a webpage, such as the word "ibf". This string could be located in any element of text on the page without a designated class. There may even be multiple elements containing the string. Here is an example snippe ...

Tips for binding data to numerous dynamic controls

Implementing reactive forms in my Angular project allowed me to create a simple form for adding employee work hours and breaks. The challenge I encountered was the inability to bind data from break controls. In the .ts file export class AddAppointmentForm ...

TypeScript is throwing an error because a value has been declared but never actually used in the

private tree_widget: ITreeWidget; private $ghost: JQuery | null; private drag_element: DragElement | null; private previous_ghost: IDropHint | null; private open_folder_timer: number | null; constructor(tree_widget: ITreeWidget) { this.tree_widget = t ...

Ensuring the proper organization of files for a pushstate/ajax website

I am currently in the process of converting my website to a fully functional HTML5 AJAX site with pushstate and popstate controlled locations. Here is my current file structure: common/header.php common/footer.php index.php page1.php page2.php page3.php ...

Received an undefined response from the CORS API request made in React

I've been attempting to make a REST API call from my local server using CORS, in order to fetch data for visualization on my React front-end. However, I'm encountering an issue where the data returned by the fetch function is undefined, even thou ...

Erase a set of characters with the press of the backspace key (JavaScript)

Within my textarea, I have lines that start with a number and a period: <textarea autoFocus id="text-area"wrap="hard" defaultValue ={this.state.textAreaVal} onKeyUp={this._editTextArea}/> For example: Line 1 Line 2 Line 3 I've created a ...

Attach an event to a shape displayed on the canvas

Is there a way to bind an event to a shape that is drawn on a canvas in HTML? I tried the following code, but it throws an error. <html> <head> <script type="application/javascript"> function draw() { var canvas ...

Locating the value of field in an array of JSON data

let data = [{ a: 1, b: 2}, { a: 11, b: 12}, { a: 31, b: 23}, { a: 51, b: 24}] How can you retrieve the object where a = 11 ? For simple arrays, one could use x.indexOf('1');. So a potential solution could be: let result = data.find(obj => o ...

Confirm the validity of decimal numbers with a precision of up to x digits beyond the decimal

Seeking to develop a Regular Expression Validation that satisfies the following criteria: a) Decimal numbers with up to 3 decimal places greater than zero b) Positive or negative non-zero numbers with up to 3 decimal places The mentioned items prefixed ...

Manipulating the content of h1 tag using Jquery when selecting from a dropdown menu

As I was exploring this Fiddle I stumbled upon, http://jsfiddle.net/JBjXN/ I've been working on a functionality where selecting an option from HTML <h1>Select a Show</h1> <select class="radio-line" id="radio-manager&quo ...

Setting up a Node.js http2 server along with an http server specifically designed for a single

In my upcoming project, I am interested in implementing the http2 protocol. My goal is to have both http and http2 servers running on a single domain and port, if feasible. When a client that does not support http2 connects, communication will default to ...

Unable to get compatibility mode IE to work as intended

I am facing an issue where I need to showcase a webpage in compatibility mode. Despite using the code below: <meta http-equiv="X-UA-Compatible" content="IE=11"> It seems like this code only functions if compatibility mode is already enabled. In tha ...

Explain the concept of DOM components in relation to refs within the React JS framework

Before this issue came up in the React documentation for ref forwarding, there was a mention: The concept of ref forwarding doesn't just apply to DOM elements. It can also be used with class components. There's a discussion on another platform ...

What are the specific pages on a three-page website that require canonical tags?

I seem to be facing an issue with Google Search Console. The error message states: Duplicate without user-selected canonical Currently, my site looks like the following. There are a total of 6 links. https://i.stack.imgur.com/s4uXF.png None of these l ...

Exploring Time Scaling and Range Adjustment in D3 Barcharts

My dataset looks something like this: dateRange = [ { date: 2017-03-23, value: 10 }, { date: 2017-03-25, value: 15 }, { date: 2017-04-01, value: 13 }, { date: 2017-04-02, value: 19 } ]; The results can be viewed here: https://embed.plnkr.co/iOBAuCZmo ...

Using Axios to Integrate an API - Displaying a Username and Password Pop-up

I have been given a project that involves API integration. I have successfully retrieved data from the API, but there is a pop-up appearing asking for a username and password. Although I have these credentials, I would like to log in without that pop-up ap ...

The design and structure of the CSS link, as well as

What motivates most developers to utilize the following links in their code: <link href="/js/jquery-ui/css/flick/jquery-ui-1.8.23.custom.css" type="text/css" /> <link href="/css/main.css" type="text/css" /> <link href="/css/table.css ...