The accordion is experiencing functionality issues

I created a customized Accordion based on a code snippet I found online to incorporate into my project, but unfortunately, it's not functioning as expected. Currently, it is displaying the address of the high school and failing to hide it when the page loads or collapse the description when the links are clicked. Despite carefully checking for errors such as typos in the classes, I have been unable to resolve the issue.

HTML

<ul class="linkLocation">
    <li class="linkHover is-active">
        <a href="#mapTX" class="linkThumb"> Austin, TX</a>
        <p class="accordion-panel">
        <address style="font-style: normal;">
        High School 1<br>
        1234 Congress Ave<br>
        Austin, TX 75087
        </address></p>
    </li>
    <li class="linkHover">
        <a href="#mapLA" class="linkThumb"> Shreveport, LA</a>
        <p class="accordion-panel">
        <address style="font-style: normal;">
        High School 2<br>
        1234 Congress Ave<br>
        Shreveport, LA 75087
        </address></p>
    </li>   
</ul>

CSS

.linkThumb {
    margin: 0;
    padding: .8rem 0;
    cursor: pointer;
    font-weight: normal;

    &::before {
    content: '';
    display: inline-block;
    height: 7px;
    width: 7px;
    margin-right: 1rem;
    margin-left: .5rem;
    vertical-align: middle;
    transform: rotate(-45deg);
    transition: transform .2s ease-out;
    }
}
.accordion-panel {
    margin: 0;
    padding-bottom: .8rem;
    display: none;
}
.linkHover.is-active {
.linkThumb::before {
    transform: rotate(45deg);
}
}

JS

$(function() {
// (Optional) Active an item if it has the class "is-active"    
$(".linkLocation > .linkHover.is-active").children(".accordion-panel").slideDown();

$(".linkLocation > .linkHover").click(function() {
    // Cancel the siblings
    $(this).siblings(".linkHover").removeClass("is-active").children(".accordion-panel").slideUp();
    // Toggle the item
    $(this).toggleClass("is-active").children(".accordion-panel").slideToggle("ease-out");
});
});

Here is the non-functional code - JSFIDDLE

Answer №1

Replace the .accordion-panel with a div. It seems that the address element is not compatible when nested inside a paragraph element.

<div class="accordion-panel">
    <address style="font-style: normal;">
    High School<br>
    1234 Congress Ave<br>
    Austin, TX 75087
</address>
</div>

Answer №2

If you're interested, take a look at this fiddle.

https://jsfiddle.net/ugrktutx/

<ul class="linkLocation">
  <li class="linkHover is-active"><a href="#mapTX" class="linkThumb"> Austin, TX</a>
    <div class="accordion-panel">
    <address style="font-style: normal;">
    High School<br>
    1234 Congress Ave<br>
    Austin, TX 75087
        </address></div>
  </li>
</ul>

$("#linkLocation > .linkHover.is-active").children(".accordion-panel").slideDown();
$("#linkLocation > .linkHover").click(function() {
//click code
});

I've made a few adjustments:

  1. Changed the linkLocation selector to an id in the js code.
  2. Switched the accordion-panel element to a div to contain the address.

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

Troubleshooting axios GET request in JavaScript: despite successfully pushing data to an array, encountering errors when using promise

I'm attempting to send a GET request to a free API in order to retrieve an array of all French departments. Initially, I encountered an issue where I was getting an empty result, which I later figured out was due to not waiting for the GET request to ...

if else within the <dd></dd> tags

I have a code snippet in Vue.js that displays a certain value. <dl> <!-- Fan speed --> <dt>{{ $t('pageInventory.table.fanSpeed') }}:</dt> <dd>{{ dataForma ...

Is there a way to eliminate the additional gap found at the bottom of a div element?

I've been encountering some difficulty when trying to insert an image into a div without any padding. The issue I'm facing is that the sizing doesn't seem to be correct; there's unnecessary extra space at the bottom. Despite my efforts ...

A guide on organizing JSX elements based on JSON data

What I Aim to Achieve: I am looking to display a list of elements using the .map method, and then arrange them in descending order based on their date. Despite attempting to use .sort and .filter before rendering the elements, I have not been successful. ...

Fetching an array through an AJAX request that triggers a PHP script

Currently, I am working on a project where I need to automatically fill a textbox by utilizing AJAX to fetch data from a PHP script that triggers a C function. In theory, this is what I have come up with: (Assuming single value reception) $(document).re ...

Tips for organizing labels and user input within an HTML document

I attempted to align inputs and labels horizontally. Here is what I tried: <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/> <div class="row"> <div class="span2"> <h2& ...

The Link Breaks the Overlay Hover Effect

Currently, the code functions as intended when you hover over or touch the thumbnail, an overlay will appear. The issue lies in the fact that to navigate to a specific URL, you have to click directly on the text. The overlay itself is not clickable and ca ...

Are MobX Observables interconnected with RxJS ones in any way?

Is the usage of RxJs observables in Angular comparable to that in React and MobX? I'm struggling to find information on this topic. ...

Capture data from ajax effectively by extracting and executing manipulations seamlessly

I have a project where I need to retrieve images from a database using Ajax and display them using a carousel plugin. This is the process: An image URL is saved to the database by an admin The frontend script makes an Ajax call to a PHP file and retrieve ...

Django-Based Navigation Bar Design for Online Shopping Site

I'm currently working on an eCommerce website using Django for the backend. I'm looking to design a dynamic navbar that will display menu options based on different categories of products. The goal is for this navbar to automatically update whene ...

Customizing Bootstrap Style for the 'btn-xs' Size Using a New CSS Class

Hey there, I'm diving into Bootstrap for the first time and I'm looking to tweak the 'btn-xs' class to adjust the height, width, and padding. I want to make the button smaller and reduce the text size as well. I attempted to create a n ...

Uploading base64 arrays from AngularJS to a Node.js server: Allowing Access-Control-Origin

My current challenge involves sending an array of base64 strings from my Client Side (AngularJs) to my NodeJs Server. However, I've encountered a peculiar situation. When I attempt to send an object containing the base64 data along with other properti ...

What is the approach for incorporating JavaScript variables in Jade templates for writing inline CSS styles?

Struggling to inject CSS code dynamically? You're not alone. style(type='text/css') #header a#logo { background:url(constants.logo) no-repeat; } @media only screen and (-webkit-min-device-pixel-ratio: 1.5) { #header a#logo { ...

The regex path matching issue in next.config.js is being caused by the pattern not being able to start with "?"

In my upcoming project, I attempted to utilize regex path matching in the next.config.js file as explained in the documentation. The goal was to match all routes except for one specific route by adding the regex ^(?!.*books). which successfully excludes an ...

What strategies can I use to refactor this controller in Angular 1.5 to make it more concise and efficient

I am encountering an issue with a component I have that contains a button. Whenever the button is clicked, it triggers one of two backend services depending on where the component is located. To achieve this, I am currently passing a flag to the component ...

Strategies for Emphasizing Individual Content Links on a Single-Page Website with Dynamic Content Replacements

My website consists of a single page with content that gets replaced using jQuery when the menu is clicked. Even though the links do not lead to different pages, just different divs, I want the menu to behave like a typical website menu with three states: ...

create a symbol marker using highchart

I recently discovered a feature in highchart that allows me to set a marker for a specific value. According to the highchart documentation: ... data: [7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, { y: 26.5, marker: { symbol: &ap ...

Best Practices for Laravel and Vue Collaboration

Currently, I am in the process of developing a straightforward invoice system using Laravel. In order to facilitate editing, I need to create a view that consists of a table where rows can be dynamically added and removed. I initially considered using jQu ...

Issue with reactivity not functioning as expected within VueJS loop without clear explanation

Struggling with implementing reactivity in vue.js within a loop? The loop renders fine, but firing an event updates the content without visibly rendering the data on the page. The latest version of vue.js is being used with bootstrap and jquery. Despite a ...

What is the process for creating an Account SAS token for Azure Storage?

My goal is to have access to all containers and blobs in storage. The Account SAS token will be generated server-side within my Node.js code, and the client will obtain it by calling the API I created. While Azure Shell allows manual creation of a SAS toke ...