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

Utilizing a dynamic value in an Angular directive

For my latest project, I am working on developing a basic JSON pretty-printer directive using angular.js. Here is the code snippet I have so far: (function(_name) { function prettyJson() { return { restrict: 'E', ...

What are the key differences between using role and class selectors in HTML 5 and CSS3 to create two sidebars with three

My decision to eliminate all ids from my CSS and transition to HTML 5 has led me to question the use of roles in markup. In the past, IDs were used to style sidebars individually within a single selector for both. Here is an example: <div id="sidebar" ...

Utilizing d3.js to implement a scatterplot with zoom functionality that focuses solely on zooming the axis without affecting

Having trouble creating a scatterplot with zoom functionality where only the axis is getting zoomed, not the data itself. Can anyone provide some assistance or insight on what might be wrong? If you're interested in checking out the project, here&apo ...

Switch out the specific content within the p tag

Looking to update the highlighted text within a p tag. The code below addresses handling new line characters, but for some reason the replacement is not working as expected. Check out the HTML snippet: <p id="1-pagedata"> (d) 3 sdsdsd random: Subj ...

Implement React-intl into the designated placeholder within the object

Currently facing an issue with the const inputProps in my code. I attempted to integrate React-intl into the react-autosuggest placeholder input, but now the placeholder text displays as: [Object object]. The getStepContent function is defined as follow ...

Is there a way to detect duplicate usernames in a form without actually submitting the form, and then automatically focus on the username field if a duplicate is

I need help with a user registration form that I am creating. I want the form to automatically search for an existing username as soon as the user starts typing in the username field. If the username already exists, I want the field to receive focus. In my ...

Ensure there is a gap between each object when they are arranged in a

Is there a way to customize the layout of elements in the ratings view so that there is automatic spacing between them? I considered using text (white spaces) for this purpose, but it seems like an inefficient solution. Are there any other alternatives to ...

What methods can be utilized to ensure that my wistia video player/playlist is responsive on different devices

I need some assistance with making my Wistia player responsive while using a playlist. I want the video player to adjust its size based on the screen size. Here is an example: My current code utilizes their iframe implementation: <div id="wistia_1n649 ...

Error in Node.js: Unable to access properties of null value within Express

While using Express (with node.js) and MongoDB, I encountered an error when trying to view or update a user profile. The middleware token check worked fine getProfileFields:::::::::::::>>>>e: TypeError: Cannot read properties of null (rea ...

Tips for accessing the names of subdirectories and files on a website

If we have the URL, is it possible to access the names of the files within the parent directory? Similar to how we can do in DOS by using the command "DIR" to view the list of files inside a folder. For example, if we have a URL like , I am curious to kno ...

Oops! Remember to always `await server.start()` first before using `server.createHandler()` in next.js

An error is popping up when I attempt to check the functionality of Apollo GraphQL. Error: You must await server.start() before calling server.createHandler() Note: Although there is a similar question regarding this issue, it is specific to Express. Error ...

having difficulty uploading an image on wampserver

I am seeking advice and assistance with an issue I am facing. I am attempting to upload an image, but Wampserver keeps displaying the following error message (Warning: POST Content-Length of 80237 bytes exceeds the limit of 750 bytes in Unknown on line 0 F ...

The functionality of ngModel is not functioning properly on a modal page within Ionic version 6

Currently I am working on an Ionic/Angular application and I have encountered a situation where I am attempting to utilize ngModel. Essentially, I am trying to implement the following functionality within my app: <ion-list> <ion-item> <ion ...

The positioning of the Zorro table column remains flexible despite the presence of nzLeft

I am currently developing a project using Angular. Within one of my components, I have a table that displays some data. This table is generated by the ng-zorro table module. However, I've encountered an issue where setting a table column or header wi ...

Unable to send information to a function (using jQuery)

I'm struggling to pass the result successfully to another function, as it keeps returning an undefined value: function tagCustomer(email, tags) { var o = new Object(); o.tags = tags; o.email = email; o.current_tags = getCustomerTags(email ...

Having trouble with Ajax POST and CodeIgniter integration?

I have encountered an issue while trying to echo back code received from Ajax. It seems that when I use contentType:false and processData:false, the functionality stops working. Below is the snippet of my ajax code. The url is correct. Interestingly, if I ...

Launching a web application directly from a USB drive

Exploring the world of Javascript frameworks and nodejs, I recently encountered a unique requirement that got me thinking about their practical application. The requirements are as follows: --I need to create a lightweight website that can be run from a U ...

Turn off automatic compilation for LESS styling

In my Eclipse environment, I am looking to have LESS compile only when explicitly triggered by mvn package. Currently, any changes made in my less file immediately update the CSS. How can I prevent this automatic behavior? <plugin> <groupId> ...

Click Action on CanJS Table

I am currently developing a canJS application and have been able to successfully handle the click event for an HTML table using the code below. 'table td click':function(el,event){ console.log('clicked ',el.text()); } ...

Turning a JavaScript function into jQuery

Is there a way to convert this JavaScript selected code into jQuery? I need to target a button class instead of an ID, and I've heard that using jQuery is the simplest way to achieve this. var playButton1 = $('.playButton1'); playButton1.o ...