Is there a way I can replicate this expandable div?

I have successfully implemented a script that expands and collapses. However, I am facing an issue when trying to use two of these scripts on the same page.

I attempted to simply add "_two" to all instances of "accordion," but it doesn't seem to be functioning correctly. What mistake am I making?

The second one is completely messed up in terms of its functionality.

<!doctype html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>unique accordion demo</title>
        <link rel="stylesheet" href="http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css">

        <script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
        <script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
        <style>
            #accordion .ui-icon { display: none; }
            #accordion a {
                border: none;
                text-decoration: none;
            }
            #accordion .ui-accordion-content { border:none; }
            #hide {
                display: none;
            }

            #accordiontwo .ui-icon { display: none; }
            #accordiontwo a{
                border: none;
                text-decoration: none;
            }
            #accordiontwo .ui-accordiontwo-content { border:none; }
            #hide{
                display: none;
            }
        </style>
    </head>

    <body>
        <div id="accordion" style="width:750px;margin-left:400px;margin-top:100px;">
            <h5 style="background:#73C7F2;text-align:center;" id="topbit"><p id="show">Click here to show Single links</p><p id="hide">Click here to hide split links</p></h5>
            <div>
                <div style="width:45%;height:40px;background:#ccc;float:left;margin-right:20px;border-radius:5px;padding-top:20px;padding-left:10px;">
                        <a href="#">Single Link Sample</a>
                </div>
            </div>
        </div>

        <div id="accordiontwo" style="width:750px;margin-left:400px;margin-top:100px;">
            <h5 style="background:#73C7F2;text-align:center;" id="topbittwo"><p id="showtwo">Click here to show Single links</p><p id="hidetwo">Click here to hide split links</p></h5>
            <div>
                <div style="width:45%;height:40px;background:#ccc;float:left;margin-right:20px;border-radius:5px;padding-top:20px;padding-left:10px;">
                        <a href="#">Single Link Sample</a>
                </div>
            </div>
        </div>

        <script>
            $(function() {
                $("#accordion").accordion({ topbit: "h5", collapsible: true, active: false});
            });

            $("#topbit").click(function(){
                $("#hide").toggle();
                $("#show").toggle();
            });

        </script>

        <script>
            $(function() {
                $("#accordiontwo").accordion({ topbittwo: "h5", collapsible: true, active: false});
            });

            $("#topbittwo").click(function(){
                $("#hidetwo").toggle();
                $("#showtwo").toggle();
            });
        </script>

    </body>
</html>

View the JSFiddle example by following this link: Unique Accordion Example.

Answer №1

The reason it's not working is because you forgot to update the second occurrence of #hide in the CSS to #hidetwo. Once you make that change, everything should function correctly:

#hidetwo{
    display:none;
}

JSFiddle

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

Verify if the expression can be found in the DIV element's style

Recently, I encountered a situation where a DIV contains a background image that is either set directly or generated as an SVG. I needed to figure out how to determine when the DIV contains the SVG-string. Here are my two DIVs: <div class="cover m ...

What is the best way to automatically increase the value of another column in SQL when the primary key is set to auto

In my database, I currently have a table storing customer details. I am looking to introduce a new column that will provide either existing or new customers with a unique auto-incremented ID for identification purposes. Additionally, I require a primary ke ...

Functionality of the Parameters Object

As I transition from using the params hash in Rails to learning Node/Express, I find myself confused about how it all works. The Express.js documentation provides some insight: 'This property is an array containing properties mapped to the named rout ...

In Internet Explorer, when utilizing a table-cell with a variable height, the position should be set to absolute for

I'm struggling with getting a uniform height in my horizontal layout using display: table-cell. While it looks great in Chrome, I can't seem to get Internet Explorer to display it the same way. Check out this link for reference This is how I wa ...

Creating a secondary ordered list with ongoing points - a step-by-step guide

Is there a way to create an unordered list with a continued ordered second level that automatically counts the points? I know about using <ol start="Previous number+1">, but is it possible for the list to continue numbering on its own? The ...

Update AngularJS data models using the callback function "on change" from a jQuery plugin

Currently, I am in the process of developing a web application for a touchscreen computer that requires an on-screen keyboard. After searching extensively, I came across this fantastic (or at least the best one I could find) keyboard plugin: https://github ...

Exploring the combination of MVC with Ajax.BeginForm and DIV.Load

I have a template that defines an Ajax.BeginForm. The model returned contains a property called ReportLink which holds the URL to a PartialView on the server. In the Ajax.BeginForm.OnSuccessFunction, I am trying to retrieve and load HTML content using $(" ...

Unable to use .click function to choose image within container

Apologies for the lengthy post, but I believe providing all details is essential to understanding the issue at hand. The following code snippet is intended to display the first image in a pop-up box when a user clicks on any of the images shown: <div ...

"Automatically close the fancybox once the form is confirmed in the AJAX success

Having an issue with closing my fancybox after submitting the registration form on my website. I am using the CMS Pro system.... Here is how I display the fancybox with the form: submitHandler: function(form) { var str = $("#subscriber_application"). ...

Tips for displaying a message in the model body when a bootstrap model does not have any data in jQuery

Having trouble displaying a text message in the Bootstrap modal body when there is no data available in the model. I have multiple cards in the model, and if I click on the skip or done buttons, each card will close. However, if there is only one card in t ...

Accessing a variable outside of the function call in AngularJS is not possible

After starting to tackle AngularJS, I've encountered an issue that's been plaguing me. It seems like I'm unable to access the data returned by $http.get() outside of the method call. Here's a look at the code snippet: (function(){ ...

Use $.ajax to display the menu by capturing an array of elements {0}

Whenever I click on one of the DIV elements, a menu pops out on the side displaying more information about the clicked element. I can determine which element I'm clicking on, but I'm struggling to pass that information from jQuery to the PHP pag ...

The jQuery countdown plugin is yielding some unexpected outcomes

Feeling a bit rushed for time, so I thought I'd ask here. The date is currently 2012-10-06 and I'm attempting to implement a jQuery plugin called "jquery.countdown.js". It seems pretty straightforward. Can anyone point out what I might be doing i ...

What are some ways to capture and save the window width prior to launching my Nuxt application?

I am working on a Nuxt application where I need to display different components based on the window width and send a request to create a session with the device width as one of the header parameters. Here is my approach: In my store code: //index.js expor ...

Angular 2: The window.crypto.subtle.importKey function functions properly on 'localhost' but encounters issues on an 'ip' address

As a newcomer to Angular 2, I am working on creating a login form that encrypts and sends the user's emailid and password to the server. I have successfully implemented AES-ECB using AES-CTR from the following link: https://github.com/diafygi/webcry ...

React's setState is not reflecting the changes made to the reduced array

I am currently working on a custom component that consists of two select lists with buttons to move options from the available list to the selected list. The issue I am facing is that even though the elements are successfully added to the target list, they ...

JQuery's .each method is executed prior to making an Ajax request

I am currently working on a JavaScript (jQuery) function that loops through input elements in a form, builds an array to convert into a JSON string, and then sends it to an AJAX endpoint. However, I am facing an issue where the loop runs after the AJAX cal ...

Displaying a single row of a PHP array in bold formatting

I have a MySQL query result showing user information and subjects they have chosen. I want to highlight one specific row by making it bold using PHP while keeping the rest as regular text. How can I achieve this? $resultSet = $db->query ("...my q ...

Currently struggling to retrieve data from an AJAX post request within a C# controller

I need assistance with sending data from JavaScript to a C# controller using AJAX. However, I am facing an issue where all the arguments in the Add method of my controller are showing up as null. Below is my AJAX code: function sendRequest(name, price, ab ...

CSS not working with fixed positioning

As part of a school project, I am required to utilize the position fixed property to correctly position the cookie statement at the bottom right of the screen. However, when I attempt to move the element, it does not seem to display properly. ...