Code Review Stack Exchange is a question and answer site for peer programmer code reviews. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Looking for feedback on how to better improve the code below to simplify the code below.

var animateTop = $('body');
if ($('html').hasClass('lt-ie9')) {
    animateTop = $('html');
$('.var').on('click', function() {
        scrollTop: $('footer').offset().top
    }, {
    queue: false,
    duration: 1500,
    complete: function() {
        if(!$('.foo').hasClass('active')) {
return false;
share|improve this question
up vote 1 down vote accepted

Can't really tell what your code does in real life, thus the following optimization/organization might not work. However, following generic tips, here's what I got:

//we can reduce DOM fetching by fetching html first
//caching it as well as other frequently used elements
//assuming that they never change in the course of your page's life
var html = $('html')
  , footer = $('footer')
  , foo = $('.foo')
  , bar = $('.bar')
  , options = {
      queue: false,
      duration: 1500,
      complete: function () {
        if (!foo.hasClass('active')) {

//then here, we fetch body only when it's not IE9+ thus reducing operations
html = html.hasClass('lt-ie9') ? html : $('body');

$('.var').on('click', function (e) {

  //i think the properties can't be cached since it may need current values
  //however, your options can be cached since they are static values
    scrollTop: footer.offset().top
  }, options);

  //an answer as to when to use return false vs preventDefault
  //you can use either, depending on the situation
  return false;
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.