Click event for jQuery horizontal accordion

I'm attempting to create a simple horizontal accordion-style element.

My setup includes three 'banner' divs and three 'area' divs. Ideally, when I click on a banner, the corresponding area should animate - expanding in width to auto and adjusting the height from min-height to auto if necessary.

While my code works fine on my website, it's not functioning properly on jsfiddle. I suspect there may be a small mistake in how I entered the code on jsfiddle:

http://jsfiddle.net/r8tvetr7/

$(document).ready(function(){
  $("#second_line_accordian_banner_one").click(function(){
    $("#second_line_accordian_area_two").animate({width:"0px"}, "fast");
    $("#second_line_accordian_area_three").animate({width:"0px"}, "fast");
    $("#second_line_accordian_area_one").animate({width:"300px"}, "slow", swing);
  });
});

$(document).ready(function(){
  $("#second_line_accordian_banner_two").click(function(){
    $("#second_line_accordian_area_one").animate({width:"0px"}, "fast");
    $("#second_line_accordian_area_three").animate({width:"0px"}, "fast");
    $("#second_line_accordian_area_two").animate({width:"300px"}, 2000, swing);
  });
});

$(document).ready(function(){
  $("#second_line_accordian_banner_three").click(function(){
    $("#second_line_accordian_area_two").animate({width:"0px"}, "fast");
    $("#second_line_accordian_area_one").animate({width:"0px"}, "fast");
    $("#second_line_accordian_area_three").animate({width:"300px"}, 1000, swing);
  });
});

Appreciate any help,

Answer №1

Check out the demo here

$(document).ready(function(){
  $("#second_line_accordian_banner_one").click(function(){
    $("#second_line_accordian_area_two").animate({width:"0px"}, "fast"),
    $("#second_line_accordian_area_three").animate({width:"0px"}, "fast"),
    $("#second_line_accordian_area_two").css( {'display':'none'}),
    $("#second_line_accordian_area_three").css( {'display':'none'}),
    $("#second_line_accordian_area_one").css( {'display':'block'}),
    $("#second_line_accordian_area_one").animate({width:"300px"}, "slow");
  }),

  $("#second_line_accordian_banner_two").click(function(){
    $("#second_line_accordian_area_one").animate({width:"0px"}, "fast"),
    $("#second_line_accordian_area_three").animate({width:"0px"}, "fast"),
    $("#second_line_accordian_area_one").css({ 'display':'none'}),
    $("#second_line_accordian_area_three").css( {'display':'none'}),
    $("#second_line_accordian_area_two").css( {'display':'block'}),
        $("#second_line_accordian_area_two").animate({ width:"300px"},600);
  }),

  $("#second_line_accordian_banner_three").click(function(){
    $("#second_line_accordian_area_two").animate({width:"0px"}, "fast"),
    $("#second_line_accordian_area_one").animate({width:"0px"}, "fast"),
    $("#second_line_accordian_area_one").css( {'display':'none'}),
    $("#second_line_accordian_area_two").css( {'display':'none'}),
    $("#second_line_accordian_area_three").css( {'display':'block'}),
    $("#second_line_accordian_area_three").animate({ width:"300px"},600);
  });
});

Answer №2

To utilize jQuery on JSFiddle, make sure to enable it in the left sidebar menu.

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

Is it possible to access a sub property using a dot string in Vue 3?

Given a Vue 3 proxy object structure as shown below: <script> export default { name: "test", data() { return { users: [{ "id": 1, "name": "Leanne Graham", " ...

What is the process for obtaining an API Key in order to access a service prior to authorization?

Alright, I have this app. It's a versatile one - can run on mobile devices or JavaScript platforms. Works across Windows, Apple, and Android systems. The app comes equipped with a logging API that requires an API key for operation. Specifically, befo ...

Creating a dynamic canvas with a three-dimensional model using three.js: A step-by-step guide

I'm currently developing a website where I have integrated a canvas element to display a 3D object (specifically, a cube) using three.js. The canvas is housed within a div, following the guidelines found in various documentation. The issue arises wh ...

Difficulty encountered when trying to update a re-updated HTML DOM using Flask

I have a flask dropzone for file uploads, and after each upload I want to display a log text on the website. While it currently works, there is an issue where the log text does not update after the second upload. The website continues to show the text from ...

What is the best way to position a button to the right side of the screen?

Is there a way to align a button to the right of a page? I attempted using text-align: right; and align-content: right; In addition, I want the button to utilize display: flex; #hideShow { display: flex; text-align: right; align-content: right; ...

What is the process for converting HTML to RTF using Java programming language?

When working with the basic API of JAVA using RTFEditorKit and HTMLEditorKit, I encountered a limitation where certain tags like <br/> and <table> were not recognized. In my search for better solutions to convert HTML to RTF, I came across two ...

The functionality of CSSTransition seems to be malfunctioning. Perhaps switching to V2 of react

Can anyone help me troubleshoot my code snippet where I'm attempting to incorporate an animation for Tooltip Nodes? Despite my efforts, the animation does not show up on the screen after mounting. Additionally, the console.log is not triggered on the ...

Seeking the method to obtain the response URL using XMLHttpRequest?

I'm having trouble with a page (url) that I request via XMLHttpRequest. Instead of getting a response from the requested url, the request is being directed to another page. requesting --- > page.php getting response from > directedpage.php ...

Retrieving PokéAPI image information

My goal is to display images from the PokéAPI on my app's homescreen when it is opened. However, I am facing a challenge where I need to call 30 different APIs in order to show 30 images. Calling these APIs one after another every few seconds seems l ...

Encountering vulnerabilities during NPM installation, attempting to fix with 'npm audit fix' but unsuccessful

While working on my react project, I decided to incorporate react-icons by running npm install react-icons in the command prompt. However, after some time, the process resulted in the following errors: F:\Areebs\React JS\areeburrub>npm in ...

Troubleshooting drag-and-drop functionality in a JavaScript HTML5 application resembling a Gmail upload interface

Here is a snapshot of my user interface: Each node in the tree structure is represented by an <li> element along with an <a> link. Furthermore, each folder serves as a dropzone for file uploads similar to the drag-and-drop feature found in Gm ...

Executing a POST Request using a Custom Node Module in Express

I'm in the process of developing a web application where the user inputs their username, submits it, and then the application processes the input through a POST request to another server. Based on the response from the external server, the user is red ...

Resize the shape of an image's polygon

Is there a way to independently scale a specific polygon of an image on hover? For example, I have a world map and I would like to enlarge a country when hovering over it, then return it to its original size when no longer hovering. I am familiar with us ...

Tips for deleting multiple objects from an array in angular version 13

I am facing an issue where I am trying to delete multiple objects from an array by selecting the checkbox on a table row. However, I am only able to delete one item at a time. How can I resolve this problem and successfully delete multiple selected objects ...

Change Scenery by Using Arrow Keys

I am trying to increase the speed of my background when the up and arrow keys are pressed. Despite my attempts, it is not working as expected. The variable this.speed controls the speed of the background. To achieve this, I implemented an if statement t ...

Struggling with finding the appropriate CSS selector?

I'm struggling to find the correct selector. Let me do my best to explain the situation: I am currently working on a project where I am unable to make changes to the HTML and JavaScript due to dynamic content and other constraints. Within this proj ...

When a new element is added to the DOM, bind a click event to it that will trigger another

When I add an element to the DOM, I bind it with a click function. The problem is that if I add multiple elements and click on any of them, the function triggers multiple times. What causes this behavior and is there a better way to achieve the desired res ...

What is the process for uploading files from NextJS directly from the browser to either Cloud Storage or an FTP server?

Is there a way to upload files from the browser using NextJS directly to Cloud Storage or an FTP server? I'm looking to upload files directly from the browser to a storage server. Do you think I can utilize node-ftp in the API routes of Nextjs, like ...

How to retrieve Rails params hash using jQuery

Can the Rails params hash be accessed in jQuery? I am looking to insert an additional key, which corresponds to a table column, into the params before submitting a form. $('#form_id').submit(function() { // perform some manipulation to r ...

What is the best way to display a bitmap image in a Div, Span, Label, etc. on an Asp.Net page without using a Handler?

I am looking to display a bitmap image within a Div element using code behind. I prefer not to use a handler for this task. Here is an example of what I would like to achieve: div.InnerHtml = BitmapImage; ...