Arrow Buttons for Expanding and Collapsing Sections on an

I'm attempting to include a downward arrow when the section is closed and an upper arrow when it's open - at the right side of each tab's head in the accordion.

Here is the HTML I have implemented. It contains for-each loops.

-- JavaScript


$(function () {


        $('tr.accordion').click(function () {

            $(this).nextUntil('.accordion').slideToggle(20);

                      
        });
    });
td.bg-light-blue{ background-color:rgb(233,242,253) }
.text-mid{ font-size:14px }
<div class="box-table" id="div_SummaryReport">
  <table class="research table text-center" id="tblSummary" width="100%">
    <thead style="position:relative;">
      <tr style="position:relative;">
        <th align="center" width="20%" style="position:relative;">&nbsp;</th>
        <th align="center" width="20%" style="position:relative;" data-toggle="tooltip" data-placement="top" title="Total Calls"> Total Calls</th>
        <th align="center" width="20%" style="position:relative;" data-toggle="tooltip" data-placement="top" title="Contacted"> Contacted</th>
        <th align="center" width="20%" style="position:relative;" data-toggle="tooltip" data-placement="top" title="#of saved calls"> Saved</th>
        <th align="center" width="20%" style="position:relative;" data-toggle="tooltip" data-placement="top" title="Percent"> Percent %</th>
      </tr>
    </thead>

    <tbody>
      @foreach (var item in Model.GroupingData) {
      <tr class="accordion">
        <td class="bg-light-blue text-mid" colspan="5"><span class="text-blue">@item.Key</span></td>

        <td class="bg-light-blue">downarrow</td>
      </tr>


      foreach (var data in item.Value) {
      <tr class="hidden-row">
        <td>@data.Name</td>
        <td>@data.TotalCalls</td>
        <td>@data.Contacted</td>
        <td>@data.Saved</td>
        <td>@data.Percentage</td>
      </tr>
      } }
    </tbody>

  </table>
</div>

The actual page closely resembles this Fiddle: https://jsfiddle.net/jmmanne/35nne25r/ This example uses plain html without any loops

Answer №1

solution showcased on fiddle, presenting the simplest method utilizing a class and a pseudoelement. Suggested to use font-awesome or an image for arrow representations, yet v and > were used as examples. https://jsfiddle.net/VeritoAnimus/avw0d9j1/1/

Update in CSS

tr.accordion td:last-child:after { float: right; }
tr.accordion td:last-child:after{ content: 'v';  }
tr.accordion.collapsed td:last-child:after{ content: '>'  }

JS Enhancements

$(function () {
    $('tr.accordion').click(function () {
                    var acdn = $(this);
        $(this).nextUntil('.accordion').slideToggle({
            duration: 20,
          complete: function () {

                /* simplifying with a different completion function if dealing with one element is feasible. However, checking the row's direction when multiple rows involved. */

              if($(this).is(':hidden') && !acdn.hasClass('collapsed'))
                acdn.addClass('collapsed');
              else if (!$(this).is(':hidden') && acdn.hasClass('collapsed'))
                acdn.removeClass('collapsed');

          }

        });
        // Alternatively, use the following line if the change event isn't essential.
        // $(this).toggleClass('collapsed');

    });
});

Noted the arrows' reversal based on your recommendation. Typically, > signifies closed status and V represents open, but can be easily switched.

tr.accordion td:last-child:after{ content: '>';  }
tr.accordion.collapsed td:last-child:after{ content: 'v'  }

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

Dealing with missing image sources in Angular 6 by catching errors and attempting to reset the source

When a user adds a blob to my list, sometimes the newly added image is still uploading when the list is refreshed. In this case, I catch the error and see the function starting at the right time: <img src="https://MyUrl/thumbnails/{{ blob.name }}" widt ...

The ng-controller (dropdown menu) is functioning properly when tested locally and on JSFiddle, however, it is not working on

My HTML website with ng-app is functioning properly when tested locally and on certain coding platforms like JSFiddle and CodePen. However, it seems to encounter issues when deployed on Google Sites, Github, W3, and similar websites. The main functionalit ...

The AJAX form fails to submit the information, causing PHP to not process the request

I encountered an issue with this particular form a few days ago which was resolved using a different PHP code provided by the helpful folks here. However, after making a small change to the form, it no longer works. I have verified that all the variables b ...

Is it possible to create two header columns for the same column within a Material UI table design?

In my Material UI table, I am looking to create a unique header setup. The last column's header will actually share the same space as the previous one. Picture it like this: there are 4 headers displayed at the top, but only 3 distinct columns undern ...

Using jQuery to fetch and read the source code of a specified URL

I'm facing an issue with extracting the source code of a website URL into a variable. Here is my current approach: <script type="text/javascript"> debugger; $(documnet).ready(function () { var timer = $.ajax({ type: ...

Having difficulty in closing Sticky Notes with JavaScript

Sticky Notes My fiddle code showcases a functionality where clicking on a comment will make a sticky note appear. However, there seems to be an issue with the Close Button click event not being fired when clicked on the right-hand side of the note. I have ...

Guide on accessing the content inside a <div> element

This is what I currently have: <div id='staff' >Staff</div> My goal is to add an asterisk after the 'Staff' text to show that the associated part is necessary. Is there a way to use CSS3 and polymer-dart to target the &ap ...

React is having trouble loading the page and is displaying the message "Please enable JavaScript to use this application."

Following a tutorial at https://learn.microsoft.com/en-us/learn/modules/build-web-api-minimal-spa/5-exercise-create-api Everything was going smoothly until I reached this step: Add the following proxy entry to package.json: "proxy": "http:/ ...

Tips for receiving a reply from S3 getObject in Node.js?

Currently, in my Node.js project, I am working on retrieving data from S3. Successfully using getSignedURL, here is the code snippet: aws.getSignedUrl('getObject', params, function(err, url){ console.log(url); }); The parameters used are: ...

Encountered an issue during deployment with Vercel: The command "npm run build" terminated with exit code 1 while deploying a Next.js web application

I've been working on a local Next.js app, but encountered an error when deploying it. Vercel Deployment Error: Command "npm run build" exited with 1 Here is the log from the build process: [08:26:17.892] Cloning github.com/Bossman556/TechM ...

Using ES6 and Typescript, when a button is clicked, apply a class to all TD elements within the button except for the first one. No need for jQuery

A sample table structure is shown below: <table> <tr> <td>1</td> <td>joe</td> <td>brown</td> <td><button onclick="addClasses()">Add Class to add TD's in t ...

The jQuery AJAX request consistently triggers the success event

I have been working on a login form that undergoes server-side validation, and now I am attempting to implement jQuery validation as well. Here is a snippet of the form: <div class="form-actions"> <button type="submit" class="btn green pull ...

Change the background color of a checkbox with jQuery by toggling it

I'm currently utilizing the Bootstrap Tree to generate a nested checkbox list (). However, I am looking to enhance the user experience by highlighting the checked items, and ensuring that when a parent is selected, its children are also highlighted. W ...

Tips on refreshing the D3 SVG element following updates to the dataset state in a React application

Hey everyone, I'm currently experimenting with D3.js and React in an attempt to build a dynamic dancing bargraph. Can anyone provide guidance on how to reload the D3 svg after updating the dataset state within REACT? Feel free to check out my codepen ...

How can you insert an image in HTML without a set path?

Converting a report from HTML to *.rtf / *.doc format <header> <img class="img" src="C:/Users/????/Desktop/Test/img/header.png" alt="img"> </header> Upon downloading the *.rtf or *.doc file, the image link may not work if there is n ...

Trigger is not activated by dynamically created element

I am dealing with a block of code that is dynamic and looks like this. var li3 = document.createElement('li'); li3.classList.add("col-sm-3"); li3.classList.add("no_padding"); var inner = ""; inner = inner ...

what is the process for incorporating a unique style in npm mydatepicker?

What is the best way to customize the style of npm mydatepicker? Here is the code I have been using: <my-date-picker [options]="myDatePickerOptions" (dateChanged)="onDateChanged($event)"></my-date-picker> Is it possible to modify its backgrou ...

Having an issue with both of my states being called simultaneously, resulting in a TypeError: Cannot read property 'map' of undefined

I am facing an issue with displaying both of my states on localhost (I am receiving the following error message: TypeError: Cannot read property 'map' of undefined). Skills.js import React, { Component } from 'react'; import ProgressBa ...

A flex container containing two divs each with a white-space:nowrap element set at 50% width

How can I create a parent div that contains two child divs, each with a width of 50% that adjusts based on content? The issue arises when one of the child divs has an h3 element with white-space:nowrap;, causing it to exceed the 50% width. I attempted to ...

Sharing data from AJAX calls in Vue using vue-resource

After using Vue resource, I'm attempting to create an AJAX call that is based on the data received from a prior AJAX call. I have successfully bound the data fetched from /me to the userDetails prop. However, when trying to pass userDetails.id into t ...