1

Hey guys I am just wondering what would be the best way to make my jQuery function a little bit more DRY.

Here is an example of my code:

    setTimeout(function(){
        $(".landing-page-header-container").addClass('reveal-signup');
        $(".landing-page-vehicle-left-container").addClass('animated fadeInLeftBig');
        $(".landing-page-vehicle-right-container").addClass('animated fadeInUpBig');
        $(".landing-close-video").removeClass('reveal-landing-close-video');
      },8000)
    });
    $('.landing-close-video').click(function(){
      $(".landing-page-header-container").addClass('reveal-signup');
      $(".landing-page-vehicle-left-container").addClass('animated fadeInLeftBig');
      $(".landing-page-vehicle-right-container").addClass('animated fadeInUpBig');
      $(".landing-close-video").removeClass('reveal-landing-close-video');
    });

Now as you can see I am repeating myself quite a bit here because the setTimeout function is doing exactly the same thing as the click function.

Is there anyway I can combine these two functions?

Thanks, Nick

1 Answer 1

1

Use a variable.

function do_stuff() {
  $(".landing-page-header-container").addClass('reveal-signup');
  $(".landing-page-vehicle-left-container").addClass('animated fadeInLeftBig');
  $(".landing-page-vehicle-right-container").addClass('animated fadeInUpBig');
  $(".landing-close-video").removeClass('reveal-landing-close-video');
}

setTimeout(do_stuff, 8000);
$('.landing-close-video').click(do_stuff);
Sign up to request clarification or add additional context in comments.

Comments

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.