1

I am sure this is ridiculously easy. I want to call another function from jQuery, or include it inline. Example:

$( "#drag-box-facebook" ).draggable({ revert: "invalid" }, function() {alert("")});

However this doesn't work, and I can't work out why.

Update To clarify, the basic function of dragging works fine, it is just that the next function isn't called.

The most basic version is obviously

$( "#drag-box-facebook" ).draggable({ revert: "invalid" });

JSFiddle

4
  • What is the intent of this? Commented Jan 30, 2014 at 22:53
  • The actual usage will be to save a simple variable in to local storage Commented Jan 30, 2014 at 22:53
  • When is the function supposed to get executed? Commented Jan 30, 2014 at 22:54
  • @crush Once the element has been dropped Commented Jan 30, 2014 at 22:55

2 Answers 2

3

You can call functions pretty easily... on start, drag, or stop. You just need to define when it runs.

$( "#draggable" ).draggable({
  start: function() {
    alert("start");
  },
  drag: function() {
     alert("drag");
  },
  stop: function() {
     alert("stop");
  }
});
Sign up to request clarification or add additional context in comments.

Comments

2

According to the jQuery UI documentation, you would have to place an event in front of the function, so that it will know when to trigger the function.

For example, if you wanted the function to be triggered when the draggable is created, you'd use:

$( "#drag-box-facebook" ).draggable({
   revert: "invalid", 
   create: function() { alert(""); }
});

Other events available are: create, drag, start and stop. The full documentation is on the jQuery UI page.

If you want it to happen when the dragging is done, you would use stop.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.