0

I have an array of objects called "Contractors" in which each contractor will be displayed in a box on the screen so they have the properties "id", "posx" and "posy". I want to be able to change the coordinates onclick from what they are currently to a line on the bottom of the screen where they will be displayed sequentially. The code for changing the coordinates works properly but animating the boxes to those coordinates does not.

function moveto(){
                $.each(Contractors, function(index, value){                 
                    $(index).animate({top: this.posy},"slow");
                    $(index).animate({left: this.posx},"slow");
                });
            }

I'm not sure where the problem is but I'm getting a problem with "Cannot read property 'Default View' of undefined". Can anyone help?

Mayur Birari
  • 5,837
  • 8
  • 34
  • 61
NodeNodeNode
  • 215
  • 1
  • 3
  • 9
  • 1
    Please, show us [a demo of your code in action](http://jsfiddle.net/). – David Thomas May 07 '12 at 20:07
  • You're passing a number to `$()`? Why? What relationship is there between each object in the array, and the elements you want to animate? – cliffs of insanity May 07 '12 at 20:08
  • @cliffsofinsanity - that's a good point. Perhaps what was intended was $("#"+index).animate(...). – Ashley Strout May 07 '12 at 20:14
  • I would test to make sure your `this.posy` and `this.posx` properties are coming through. – mattsven May 07 '12 at 20:20
  • 1
    Ahhhhh thanks so much cliffs! You were completely right, I forgot to select the divs themselves :D if you want to see it, check it out here http://jsfiddle.net/lmalcom/4cWWD/1/embedded/result/ – NodeNodeNode May 07 '12 at 20:26
  • 1
    @coderkid DOM ID's can not start with a number http://stackoverflow.com/questions/70579/what-are-valid-values-for-the-id-attribute-in-html – Matt May 07 '12 at 20:29

1 Answers1

0

index is a number, so it makes no sense to put it in a jQuery object or call functions on it.

Actually, there are no DOM elements in your function at all, so without seeing more of your code it is impossible to fix.

ThiefMaster
  • 310,957
  • 84
  • 592
  • 636