By jsfiddel link you want to get drag and drop function. jQuery Draggable UI already provides this feature, why can't you use it?
To create a custom event in your path, you must follow two alternative methods.
$('your selector').on( "myCustomEvent", { foo: "bar" }, function( event, arg1, arg2 ) { console.log( event.data.foo ); // "bar" console.log( arg1 ); // "bim" console.log( arg2 ); // "baz" }); $( document ).trigger( "myCustomEvent", [ "bim", "baz" ] );
In the example above
In the world of custom events, there are two important jQuery methods: .on () and .trigger (). In the Events chapter, we saw how to use these methods to work with custom events; For this chapter, it is important to remember two things:
.on () takes an event type and an event handling function as arguments. In addition, it can also receive event-related data as its second argument by pressing the event-processing function on the third argument. Any transmitted data will be available for the event processing function in the data property of the event object. The event handling function always takes an event object as its first argument.
. The trigger () method takes an event type as an argument. If desired, it can also take an array of values. These values will be passed to the event processing function as arguments after the event object.
Here is an example of using .on () and .trigger (), which uses user data in both cases:
OR
jQuery.event.special.multiclick = { delegateType: "click", bindType: "click", handle: function( event ) { var handleObj = event.handleObj; var targetData = jQuery.data( event.target ); var ret = null;
In the example above
This special multiclick event maps itself to the standard click event, but uses a handle to the handle so that it can track the event and only deliver it when the user clicks on an element multiple of the number of times specified during the binding event.
The hook stores the current number in the data object, so multiclick handlers on different elements do not interfere with each other. It changes the type of the event to the original multiclick type before calling the handler and restores it to the display type "click" before returning: