Expanding/Collapsing Indicator Stays in Place as Content Expands

I'm encountering a problem with my expand/collapse code. I want the p class="heading" tag in the HTML (which is responsible for toggling my expand/collapse box) to move down along with the expanding content. At the moment, the content expands and appears below the toggle.

I attempted to create a fiddle of the code, but the expand function wasn't functioning properly, so I regret that I can't provide one.

Here's the snippet of the code causing the issue:

CSS

<style>
/* mouse over link */
p {
color: rgb(206, 134, 57);
margin-left: -10px;
margin-right: -10px;
margin-bottom: 0px;
transition: background .75s ease-in-out, box-shadow .5s ease-in-out;
}
p:hover { text-decoration: underline;
cursor: pointer;
color: rgb(206, 134, 57);
-moz-box-shadow: 0 -2px 2px;
-webkit-box-shadow:  0 -2px 2px;
box-shadow: .1px .1px 5px .1px #787878;
}
.heading {
font-family:Arial, Helvetica, sans-serif;
font-size:13px;
text-align: center;
padding:7px 14px 7px 12px;
border-bottom-left-radius:5px;
border-bottom-right-radius:5px;
text-decoration:none;
background: -moz-linear-gradient(top, #dedede, white 75%);
background: -webkit-gradient(linear, 0 0, 0 75%, from(#dedede), to(white));
border-top: 1px solid #A6A6A6;
outline:none;
}
a {
color: rgb(206, 134, 57);
}
.heading:hover {
transition: background .75s ease-in-out, box-shadow .5s ease-in-out;
}
a:hover {
color: rgb(137, 90, 39);
}
.transition {
border: 1px solid #A6A6A6;
border-radius: 5px;
background:white;
padding-top: 7px;
padding-right: 10px;
padding-bottom: 0px;
padding-left: 10px;
transition: background .75s ease-in-out, box-shadow .5s ease-in-out;
}
.transition:hover {
background:#e6ebef;
box-shadow: .1px .1px 5px .1px #787878;
transition: background .75s ease-in-out, box-shadow .5s ease-in-out;
}
</style>

JQuery/JavaScript

<script type="text/javascript">
jQuery(document).ready(function() {
jQuery(".content").hide();
//toggle the componenet with class msg_body
jQuery(".heading").click(function() {
var s = $(this);
jQuery(this).next(".content").slideToggle(500);
s.html(s.text() == 'Click here for less information...' ? 'Click here for more information...' : 'Click here for less information...');
});
});
</script>

HTML

<div class="transition"><span style="font-weight: bold; font-size: 18px; color: rgb(0, 130, 200);"><u>Tree Removal Permit</u><br>
    </span> <br>
    A tree removal permit is required for removal of any tree on a commercial or multi-family property.<br>
    <p class="heading">Click here for more information... </p>
    <div class="content">
    <div style="height:7px;font-size:7px;"> </div>
    <span style="font-size: 14px; color: rgb(6, 78, 137);"><b>Online Application Process</b></span>
    <ul>
        <li type="square">For an easy, step-by-step permit application process visit our Online Licensing and Permitting Portal</a>.</li>
    </ul>
    <div style="height:7px;font-size:7px;"> </div>
    </div>
    </div>

Any assistance would be highly appreciated!

Answer №1

Make sure to move your <div class="content".. above the "See Less" button. Place it before the <p class="heading".. line and update this section accordingly:

jQuery(this).next(".content").slideToggle(500);

to

jQuery(this).prev(".content").slideToggle(500);

Answer №2

Did you mean this? https://jsfiddle.net/creativecoder/7asjd9e/

To achieve the desired layout, you must relocate the "p" tag below the "content" div and update the JavaScript code as shown:

jQuery(document).ready(function() {
    jQuery(".content").hide();
    //toggle the component with class msg_body
    jQuery(".heading").click(function() {
        var element = $(this);
        jQuery(".content").slideToggle(500);
        element.html(element.text() == 'Show less' ? 'Show more' : 'Show less');
    });
});

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

Cross-Origin pre-flight OPTIONS request not allowed

Latest Updates and Root Cause I am currently developing a client-side application that is designed to communicate with Phil Sturgeons' CodeIgniter REST application. The main problem arises when attempting to access the login method, where I encounte ...

Send the fullcalendar event objects array to the backend

Struggling to send fullcalendar events to my Django backend, I noticed that AJAX is not transmitting the correct data. Any advice on how to properly transfer these events to the backend? $.ajax({ url: '/home/update_event/', method: 'POST ...

Having trouble invoking the "done" function in JQuery following a POST request

I am currently working on a Typescript project that utilizes JQuery, specifically for uploading a form with a file using the JQuery Form Plugin. However, after the upload process, there seems to be an issue when trying to call the "done" function from JQue ...

Using Rails 3 with jQuery Mobile for remote AJAX calls, processing data as HTML

I've been browsing through multiple discussions on this topic and even watched the Railscast about mobile detection (#199). My rails3 application utilizes jquery, ajax, and format.js successfully. Now, I'm attempting to expand its functionality t ...

Transferring JavaScript variables to a frame

Struggling to integrate dynamic parameters from the URL into a frame, but nothing seems to be working. I've tried placing them inside and outside the tags, before and after... Anyone have any insights on this? The URL in the top frame is . The initia ...

Navigating through object keys in YupTrying to iterate through the keys of an

Looking for the best approach to iterate through dynamically created forms using Yup? In my application, users can add an infinite number of small forms that only ask for a client's name (required), surname, and age. I have used Formik to create them ...

Clearing the JSON data from the file object

I am encountering an issue that requires me to pass some information along with a file to a controller using an Ajax call. The model structure is as follows: public class PersonModel { [Display(Name ="Full Name")] public string Name { ...

Creating a custom CSS counter-style reminiscent of the toLocaleString function

Is there a way to customize the list counter style to display commas in the thousands place, similar to number.toLocaleString()? Or perhaps even adjust based on locale to show either 1,234 or 1.234? I have checked the Predefined counter styles but did not ...

Function for jQuery dropdown panels

I am currently facing an issue with my dropdownpanel function for a data table. The problem is that the function only seems to work on the first button. I am trying to toggle the panel by adding and removing the "visible" class. Can anyone help me troubles ...

What steps can I take to stop Firefox from automatically adding vertical scrollbars to a select dropdown when I change the background color?

Having an issue with changing the background color of a select dropdown. It works fine in Chrome and Safari, but when I try to change the background color in Firefox to anything other than #FFFFFF, the appearance of the dropdown changes drastically. It see ...

What is the best way to pass an email as a Laravel parameter within a function using Angular?

I'm currently working on a feature that allows users to delete their account only if the input field matches their email address. However, I encountered an error: Error: $parse:lexerr Lexer Error when attempting to set this up. Here is my HTML code: ...

Modify css using jquery for multiple ids assigned to the same class

I have a set of 3 divs all sharing the same class. <div id="qq1" class="cl">sentence</div> <div id="qq2" class="cl">sentence</div> <div id="qq3" class="cl">sentence</div> I am interested in finding out how to properly ...

ng-bind-html not refreshed following ng-click triggering

Recently, I started learning about the MEAN stack. I have implemented an ng-repeat in my HTML code that displays a list of titles. Each title has an ng-click function attached to it, which is supposed to show more details in an overlay popup. blogApp.co ...

Karma-coverage examines the test coverage of JavaScript files rather than TypeScript files within Angular 2

I am facing an issue with checking test coverage in TypeScript files using Istanbul and setting test thresholds via karma-coverage. The problem arises because karma-coverage checks test coverage in JavaScript files instead of TypeScript, which leads to mis ...

Looking to retrieve the <td> element using the class name?

When a specific condition is met in the class name, I want to apply styles to an entire row. The table structure I am working with is as follows: <table> <tbody> <tr> <td><div><span class='level2'></span&g ...

Error: Property id in jQuery is missing colon after it in the syntax

I have implemented jQuery to handle the action of clicking a submit button. While validating a form, I only need a single value from the form rather than all of them. Everything seems to be functioning correctly, but I am encountering an error during execu ...

Choose the elements that do not possess a specific class as their ancestor

I'm facing an issue with my HTML code. Here's what it looks like: <div class="asd"> <audio src="..."> </div> <audio src="..."> <audio src="..."> <audio src="..."> My goal is to select all of the audio el ...

Using a JSON file as a database for a project featuring HTML, CSS, and Vanilla JavaScript

Our task was to create a project that exclusively utilized JSON files for data storage. The data structure we were working with resembles the following: [ { "aircraftName": "Boeing 747", "departDate": 1640173020000, ...

Interact with CakePHP using onKeyUp event

Hey there, I have a quick and easy question. I'm working with a textbox that needs to trigger a javascript/jquery function whenever it is typed into. <?= $this->Form->input('contract_prices.'.$num.'.quantity', [ 'id ...

The Bootstrap dropdown menu unexpectedly appears in front of the panel located above

Having trouble with the Bootstrap dropdown panel. My web page has 4 main panels, each containing additional bootstrap panels. When I open one panel at a time, everything works fine. However, when I try to open multiple panels simultaneously, the positions ...