Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8140547
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T12:11:57+00:00 2026-06-06T12:11:57+00:00

Heres my custom function called doIt which as im sure you can see simply

  • 0

Heres my custom function called “doIt” which as im sure you can see simply allows someone to call .doIt() on a class or id and in this case makes the background color red and then makes the element draggable. (this is my first attempt so please be nice).

(function($) {
   $.fn.doIt = function(customOptions) {
      var options = $.extend({}, $.fn.doIt.defaultOptions, customOptions);
      return this.each(function() {
         var $this = $(this); 
         $this.on('click', function(e){
            e.preventDefault();
            $this.css("background-color", options.color);
            $this.draggable();
         });
      });
   };
   $.fn.doIt.defaultOptions = {
    color: "#000"   
   };               
})(jQuery);

because my function makes the element draggable I would like to use some of events tied to draggable like ‘stop’ for example so when the dragging has stopped I would like the user to be able to access the same event/ui info in the callback of stop.

However how can I interact with the stop event of draggable from my function?

What Im expecting to see is somethign like:

$("div#test").doIt({
    color: "#ffeeaa",
    stop: function(e, ui){

      //interact with draggable event/ui here.  
      //So 'e' and 'ui' would return me what the 'stop' event from draggable would normall return.

    }
});

Is this possible to do or am I barking up the wrong tree?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T12:11:58+00:00Added an answer on June 6, 2026 at 12:11 pm

    You just need to pass your options to jQuery. Obviously, you are defining options above and beyond what jQuery uses, so you’ll probably want to filter out the ones that jQuery doesn’t care about, but I’m pretty sure that you don’t have to; jQuery will just ignore the properties that it doesn’t use.

    So, you are specifically trying to hook into the stop event. To do this, change this line:

    $this.draggable();
    

    to this:

    $this.draggable({
        stop: customOptions.stop   // Get the callback defined in custom options
    });
    

    If you don’t have any naming collisions between your custom options and the options that jQuery defines, you could probably just do this:

    $this.draggable(customOptions);
    

    jQuery will call your function (passing the event and ui parameters to it) once the user has stopped dragging your draggable element.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I simply want a class that does this: class cleanup : boost::noncopyable { public:
I have a function called DrawPlaybook which listens to two events, one mouseclick event
Here is my custom class that I have that represents a triangle. I'm trying
Here I only want to pass a custom class or only parameters into a
I have a custom UITableViewCell , which have a button on it, IB linked
This is a question on making custom fields in Django. I'm making a field
Scenario: There are multiple C structs, each of which contains a function pointer to
I'm new to Matlab and I'm trying to write custom function in matlab that
The setup: One server class (extension of AbstractService) One cometd client (custom C implementation,
I'm creating a jQuery plugin which adds some custom animations to an element and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.