Andrew
Andrew

Reputation: 359

Jquery list update

I currently have a drag/drop list my problem being I'm trying to detect when a div is dropped via Jquery using mouseup.

The problem being the reason I need to do this is so I can update my lists (in MYSQL) - I plan on doing this using a Jquery Ajax post.

My problem is I've set up the code and I don't know where I am going wrong - in my code you will see an alert function - I used this to show if the div was updating.

So far I am receiving no alert..

Here is the jquery at the moment:

$(document).ready(){
$(.mouseup).mouseup(function(){
var divparent = $(this).parent().attr("id");
alert(divparent);
});
}

Any help would be appreciated.

Thank you in advance!

Upvotes: 0

Views: 66

Answers (3)

Jamie Dixon
Jamie Dixon

Reputation: 54021

As far as I know, the mouseup event won't fire when you release your mouse away from the original location of the element you were dragging.

One way to solve this is to set the mouseup event on the body instead and detect which item you were dragging to begin with.

Upvotes: 0

Kyle
Kyle

Reputation: 22278

I put some arrows where things need to change.

$(document).ready(function(){ // <-----------------
  $(".mouseup").mouseup(function(){ // <--------------
    var divparent = $(this).parent().attr("id");
    alert(divparent);
  });
}); // <---------------

Upvotes: 2

edhedges
edhedges

Reputation: 2718

I am assuming you have a class named .mouseup in your html so you need to make sure jquery knows that.

this line: $(.mouseup).mouseup(function(){

should be: $('.mouseup').mouseup(function(){

You also don't need the .ready check.

If you want to keep the .ready @Kyle has it correct.

Upvotes: 1

Related Questions