tim.baker
tim.baker

Reputation: 3307

Call another function with jQuery

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

Upvotes: 1

Views: 92

Answers (2)

Victoria Ruiz
Victoria Ruiz

Reputation: 5013

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.

Upvotes: 2

Gavin Pickin
Gavin Pickin

Reputation: 742

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");
  }
});

Upvotes: 3

Related Questions