Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6616575
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:35:58+00:00 2026-05-25T20:35:58+00:00

I am trying to setup a simple example where a user can click a

  • 0

I am trying to setup a simple example where a user can click a button on a page and divs are moved from one side of a parent div to another. If the button is clicked again the divs should move back to their original position.

I have successfully set this up, but the code feels a little clumsy to me. Can anyone recommend a cleaner way to do this than what I have done below:

var operator = '+=';
$('#clickme').click(function() {

    $('#main div:even').animate({
        left:operator + '200'
    }, 2000);

    if(operator == '+='){operator = '-=';}
    else{operator = '+=';}
});

The if/else at the end of my click event is the part that seems odd to me. Any suggestions for prettying this up?

You can play with the fiddle here:

http://jsfiddle.net/S6UtE/3/

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T20:35:58+00:00Added an answer on May 25, 2026 at 8:35 pm

    I would keep the += and change the 200 to -200 and back again:

    var move = 200;
    $('#clickme').click(function() {
        $('#main div:even').animate({ 
            left:"+="+move
        }, 2000);
        move = -move;
    });
    

    http://jsfiddle.net/S6UtE/7/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to compile a simple cython extension from the example page here
I'm trying to set up the simple syndication example from the Django docs, in
I'm trying to setup a simple timer that gets started from a Rails Application.
I am trying to setup a simple database in which I have a user
I am trying to implement a simple plist example from Beginning iPhone 3 Development
I'm trying to set up a Spring JPA Hibernate simple example WAR for deployment
I am trying to setup a simple demo of activemq and mina. I edited
I'm trying to set up a simple server side RSA encryption of a small
I'm trying to create a setup project and I can't believe how painful it
I'm trying to get a simple example working with GCDAsyncSocket, and am discovering that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.