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

  • SEARCH
  • Home
  • 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 8479747
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:07:05+00:00 2026-06-10T19:07:05+00:00

I have used this example for a Jquery Live Dragable: jQuery Drag And Drop

  • 0

I have used this example for a Jquery Live Dragable:

jQuery Drag And Drop Using Live Events

But want to convert it to use the .on in jquery 1.7 tried all sorts of permutations can anyone help?

Here is my working code using .live to create a .livedragable method:

(function ($) {
$.fn.liveDraggable = function (opts) {
  $(this).live("mousemove.liveDraggable", function() {
      $this = $(this);
     $this.draggable(opts);
      $this.off('mousemove.liveDraggable'); // kill the mousemove
  });
  return $();
 };
}(jQuery));

Here is the call to the livedraggable:

    $(".item").liveDraggable({
            revert: true
    });

I am using this because I have a number of draggables that are loaded via ajax from a DB.

I have now tried:

    this.on("mousemove",".liveDraggable", function() {

but it doesn’t work.

UPDATE
Finally got to this via Joel Purra’s answer (see below) and it works great!!

(function ($) {
  $.fn.liveDraggable = function (draggableItemSelector, opts) {
    // Make the function chainable per good jQuery plugin design
    return this.each(function(){
      // Start the event listener for any contained draggableItemSelector items

    $(this).on("mouseenter", draggableItemSelector, function() {
        var $this = $(this);

        // If the item is already draggable, don't continue
        if($this.data("is-already-draggable") === true)
    {
      return;
    }
    // Make the item draggable
    $this.draggable(opts);

    // Save the fact that the item is now draggable
    $this.data("is-already-draggable", true);
     });
   });
  };
}(jQuery));

Plus the selector

$(function() {     
  $("#my_div").liveDraggable(
   ".item",
    {
      revert: true
   });
});
  • 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-10T19:07:07+00:00Added an answer on June 10, 2026 at 7:07 pm

    Edit: I would call the custom .liveDraggable(...) function on a container that contains all .item that you will add from your database. The function and call needs to be rewritten though. Try this piece of code. I also switched to the mouseenter event, since it doesn’t execute as often as mousemove – but enough times to keep functionality.

    (function ($) {
      $.fn.liveDraggable = function (draggableItemSelector, opts) {
        // Make the function chainable per good jQuery plugin design
        return this.each(function(){
          // Start the event listener for any contained draggableItemSelector items
          this.on("mouseenter", draggableItemSelector, function() {
            var $this = $(this);
    
            // If the item is already draggable, don't continue
            if($this.data("is-already-draggable") === true)
            {
              return;
            }
    
            // Make the item draggable
            $this.draggable(opts);
    
            // Save the fact that the item is now draggable
            $this.data("is-already-draggable", true);
          });
        )};
       };
    }(jQuery));
    

    Call the function once, when your page loads. This assumes you will add your .item inside <div id="my-item-container"></div>.

    $("#my-item-container").liveDraggable(
      ".item",
      {
              revert: true
      });
    

    Original answer: You might be mixing up the syntax for jQuery’s CSS selectors and jQuery’s event namespacing.

    The event you are listening to in your .live(...) call, mousemove.liveDraggable is only fired from the .liveDraggable code if the event has been explicitly namespaced – and I don’t see any such code in your example. Listening to the event won’t work, as it will be filtered out by jQuery. The same goes for .on(...).

    You can still use .on("mousemove", ".liveDraggable", function ...) if you are using the class .liveDraggable to distinguish your draggables.

    Since you are turning off the listener right away, also have a look at .one(...).

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

Sidebar

Related Questions

I have used scrolling script from this site. http://blog.waiyanlin.net/example/jquery/flyingtext.html . I need the animation
I have used this custom grid view in my code, and I want to
I have used this code for extracting urls from web page.But in the line
I have used this function to convert string to bits. def a2bits(chars): return bin(reduce(lambda
I used this example to hide and show some divs on my site: http://papermashup.com/simple-jquery-showhide-div/
I have used this header in my site: <head> <script type=text/javascript src=libs/jquery.js></script> <script type=text/javascript
I have never used Prototype before. But now when I'm using Rails, it seems
I have implemented HTML tooltips in d3.js following this example , using code like
I have used this code (kind of tutorial) at http://code.google.com/p/gwt-examples/wiki/gwt_hmtl5 ... In this code,
I have used this website for testing http://www.webpagetest.org and among some suggestions for optimization

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.