0

I have a JavaScript code and there is one function that I want to add two class to it , but if I add them in the same function line the other class don't work , and when I write each one in the same function but different lines the second class works only , all what I want here is add the first class and add the second class after like 5sec ? I don't know if there is any way to make it work but I hope there is .

this is when the first class only works :

function open() {
        en.addClass('op').addClass('bo-ac')
            .removeClass('cl');
    }  

this is when the second class only works :

function open() {
            en.addClass('op')
                .removeClass('cl');
        }  

 function open() {
         $('.bo').addClass('bo-ac')
    }
4
  • You have two open() function declarations, so the second one overwrites the first one. Commented Mar 12, 2021 at 5:48
  • I think it will be useful if you mentioned why you wanna do this Commented Mar 12, 2021 at 5:49
  • @VLAZ is there a way that i can add the two classes together and make one work before the other ? Commented Mar 12, 2021 at 5:49
  • @S.Alvi the first class is an animated thing so i want the animate works the the second class to execute Commented Mar 12, 2021 at 5:51

1 Answer 1

1

@Nothere. I'm not sure, but is this something you are looking for ?

function open() {
    en.addClass('op').removeClass('cl');
    setTimeout(function() {
       en.addClass('bo-ac')
    }, 0)
} 
Sign up to request clarification or add additional context in comments.

2 Comments

Yeah thank you so much , it worked , but can i do any thing to delay the time of the second class execution ?
You can try adding time in milliseconds instead of 0 as the second argument for setTimeout function. say for 5 seconds delay u can add 5000. But please note, 5 seconds is the minimum delay here and it might take more than that as well to execute.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.