MilkACow
MilkACow

Reputation: 67

Jquery Droppable into array

I am trying to use droppable jquery and grab each of the item and put it into array, but it isn't working as intended.

Basic concept:

var array= [];
$("").droppable({
   drop: function( event, ui ) {
      array.push($(this).text());
....

Let's say I drop "Chocolate", then I drop "Banana" into the droppable div above, some reason the array turns to be [Chocolate, ChocolateBanana]

I can't figure out how to get it to separate correctly to show [Chocolate, Banana].. any suggestions?

Upvotes: 0

Views: 184

Answers (2)

MilkACow
MilkACow

Reputation: 67

I resolved it, but not a "sexy" method.

Create a temporary integer and sum up all the length from previous array.. then use slice and remove the length of the sum. Then PUSH to the array.

Now I can move on and figure sorting issue.. probably yet another temporary variable array.

Upvotes: 0

Norman Skinner
Norman Skinner

Reputation: 6985

After you push, try clearing $(this).text()?

Upvotes: 1

Related Questions