Reset all modifications made by jQuery animations before initializing a fresh animation

Is there a way to reset the changes made to the first div before animating the second div using jQuery animation?

      $(".order-b").click(function(event){
        $(".order-t").animate({top:'30%'}, "slow" );
      });

      $(".counsel-b").click(function(){
        $(".counsel-t").animate({top:'30%'}, "slow" );
      });


<div class="process-bars">
   <!-- first DIV -->
   <div class="order-b">
      <div class="order-t">
          <i class="fa fa-shopping-cart"></i>
          <h1>Order</h1>
      </div>                                      
   </div>

   <!-- Second DIV -->
   <div class="counsel-b">
      <div class="counsel-t">
          <i class="fa fa-shopping-cart"></i>
          <h1>Order</h1>
      </div>                                        
   </div>
</div>

CSS code:

.order-t, counsel-t {
position:absolute;
top:52%;
width: 100%;
margin:0 auto;
z-index:2;

}

I am looking for a way to clear the animation of the first div when clicking on the second div without implementing code like the one below. How can I achieve this?

     $(".order-b").click(function(event){
        $(".order-t").animate({top:'30%'}, "slow" );
        $(".counsel-t").animate({top:'52%'}, "slow" );
      });

Answer №1

As demonstrated in this explanation: , you can effectively remove any CSS styles that have been applied to an element using jQuery by utilizing the following code snippet:

$('.element').removeAttr('style');

Answer №2

To trigger the second animation only after the completion of the first one, you can utilize a callback function with the .animate() method:

$(".counsel-b").click(function(){
  $(".order-t").animate({top:'52%'}, "slow", function(){
      $(".counsel-t").animate({top:'30%'}, "slow" );
  });          
});

FIDDLE

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 enable autocomplete for JavaScript generated code in .proto files?

I recently created a basic .proto file with the following content: syntax = "proto3"; message Event { optional string name = 1; } After downloading and installing the protoc linux compiler (protoc-3.19.3-linux-x86_64.zip) on my local machine, ...

Display top level option while in Level 2 menu on Woocommerce

Looking to implement an accordion menu for mobile devices on a WordPress Woocommerce site. I've tried various code snippets from other sources but haven't been successful so far... The current code only supports 2 levels of the accordion menu. H ...

Issue with jqGrid Multiple Selection

When constructing my jqgrid, I utilize the following code: multiselect: true This enables a check all column. However, clicking the check all checkbox (located at the header) selects all checkboxes, but does not click the checkboxes in each row. You can ...

Looking for assistance in reducing the vertical spacing between divs within a grid layout

Currently, I am in the process of developing a fluid grid section to showcase events. To ensure responsiveness on varying screen resolutions, I have incorporated media queries that adjust the size of the div elements accordingly. When all the divs are unif ...

Is there a way to transfer a value from one JS function to another in Node.js?

I am struggling to retrieve the return value from a JavaScript function in Node.js and pass it back in a POST method within my server file. Despite my efforts, I keep receiving an undefined result. What could be causing this issue? My objective is to retur ...

Using Selenium to extract and manipulate text content enclosed within specific HTML tags

Imagine you have this snippet of HTML code <tag1> "hello" <tag2></tag2> "world" </tag1> If we use driver.find_element(By.CSS_SELECTOR,"tag1").text, it will display the string "helloworld". ...

I am facing an issue where both curl and file_get_contents are not functioning properly after

When attempting to access a user's city information using coordinates, I have encountered an issue with the response not being displayed in my console. The process involves a javascript function that takes latitude and longitude data, sends it to a PH ...

I am experiencing issues with the indentation not working properly in Bootstrap 5 within my Angular 15 project

While working on my project, I have encountered a problem where I am unable to apply Bootstrap's paddings and margins to my inner elements. Despite following all the necessary syntax and nesting rules, I am facing issues. Here is a snippet of the mark ...

deleting a aircraft upon the addition of another in three.js

I am striving to implement a button that toggles between different terrain-generating functions and removes the previous terrain. The current issue I am facing is that the planes stack on top of each other. You can see an image of the problem here. There ...

troubles with dividing string

Recently delving into JavaScript/Angular development and encountering a little roadblock. I am attempting to break up a string of a textarea into an array at the \n character within a controller by utilizing $scope.mytext.split("\n"), however, I ...

Utilizing Angular to integrate with an external API

I have encountered an issue while trying to connect to the Expedia API. In order to do so, I need an API key and ID. Initially, I utilized JSONP for this connection but ran into a bug causing problems. Additionally, storing my API key in JavaScript poses ...

Error in JavaScript: A surprise anonymous System.register call occurred

Within Visual Studio 2015, there exists a TypeScript project featuring two distinct TypeScript files: foo.ts export class Foo { bar(): string { return "hello"; } } app.ts /// <reference path="foo.ts"/> import {Foo} from './f ...

What is the best way to add a filter to a nested array?

I am currently facing a challenge in creating a multiple filter for multiple arrays without duplicating the nested array. I am working with vuejs and some plugins that are relying on the array, so my only option is to filter it without modifying it. Using ...

Using Bootstrap's fourth version grid system

Struggling with creating a layout on bootstrap4? Here's a code snippet to help you out. Thank you in advance! <div class="col-8"> <a href="#"> <div class="card"> <img class="card-img" src="img.jpg"> ...

"PHP's isset function causes an infinite hang when trying to set a radio

When processing each question <input> set, some questions have radio button answers while others have checkboxes... Upon submitting, the data is inserted into the database $i = 1; while($i<6){ if(isset($_POST['radio' . $i])){ (MY ...

What is the trick to showing text underneath a font awesome icon?

My HTML code contains font awesome icons, and I'm looking to have text appear below each icon instead of next to it. Currently, the text is displayed midway to the right of each icon. <div class="icons"> <span class="fa-stack f ...

Convert Jupyter notebook to an executable html file

Looking for a way to export a Jupyter notebook in HTML to get an executable version? Currently, I upload the notebook to a git repository and use binder to obtain its executable form. However, I want to directly upload the notebook to my website without ha ...

Pagination in Datatables

Here is the code snippet I am working with: $('#ldap-users, #audit-users').dataTable({ "sDom": "<'row'<'span6'l><'span6'f>r>t<'row'<'span6'i><'span6'p& ...

Sending a JSON object with scheduled task cron job

I have a PHP cron job that is quite complex. It retrieves data from an external webpage and consolidates all the information into one variable, encoding it in JSON. Unfortunately, this entire process is slow and consumes a significant amount of time. My d ...

Using strings "true/false/null" in React Map render instead of true/false/null values

Imagine working in React, where I am looping through JSON data stored in the state variable this.state.searchData. Some of the data values returned from the API call may include true, false, or null. Here is an example: "active": true, "partition": n ...