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 6354911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:39:36+00:00 2026-05-24T22:39:36+00:00

jQuery + JavaScript var movable = new Array(); movable.push($(‘#cloud1’)); movable.push($(‘#comment1’)); if(left == true){ for(i

  • 0

jQuery + JavaScript

       var movable = new Array();
       movable.push($('#cloud1'));
       movable.push($('#comment1'));

        if(left == true){ 
            for(i = 0; i < movable.length; i++){
                movable[i].position().left += 10;
                movable[i].css("left", movable[l].position().left);                   
            }
        }

I’m trying to move a set of objects across the screen while the left arrow key is pressed. I’ve added two objects to an array, and i’m then attempting to loop through the array, increment that objects position, and then update its css. However the position of the object always stays the same which i’ve checked using:

            alert(
            "Size: " + movable.length +
            "\nIndex 0: " + movable[0] +
            "\nLeft: " + movable[0].position().left + 
            "\nTop: " + movable[0].position().top 
            ); 

Can you see why it’s not working? Or tell me a better approach. Thanks!

Working code:

for(l = 0; l < movable.length; l++){
    var tmpPosX = movable[l].position().left;
    tmpPosX += amount * 10;
    movable[l].css("left", tmpPosX);                   
}
  • 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-24T22:39:37+00:00Added an answer on May 24, 2026 at 10:39 pm

    .position() is not a ‘set’ method; you can only use it to get the position.

    http://api.jquery.com/position/

    movable[i].offset({left:movable[i].position().left+10}) should work, though.

    http://api.jquery.com/offset/#offset2

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

Sidebar

Related Questions

Javascript/JQuery var gallerynr = 3; var thumbsnrA = new Array(gallerynr); var a = 0;
I am trying to find an equivalent for the following jQuery javascript: var x1
Given the following javascript (jquery) $(#username).keyup(function () { selected.username = $(#username).val(); var url =
The following jQuery Javascript code is included on an otherwise empty page. var element;
<head runat=server> <title></title> <script language=javascript type=text/javascript src=Scripts/jquery-1.6.2.js></script> <script language=javascript type=text/javascript src=Scripts/json2.js></script> </head> var EmployeeSerialized
New to SO and javascript. I have been playing with JQuery for a couple
I'm new in jquery/javascript and couldn't google for any solution. I have number of
Classic javascript: var myvar = document.getElementById(abc); abc.value += test; abc.value += another test; Jquery:
I'm new to jQuery/JavaScript, so please forgive me me things don't make sense. I
I am new to Jquery and Javascript. Need a help regarding this problem: There

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.