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 6971365
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:49:51+00:00 2026-05-27T16:49:51+00:00

i am using a jquery plugin to create some draggable objects. the plugin is

  • 0

i am using a jquery plugin to create some draggable objects.

the plugin is here and demos are here.

Also my testing with jsfiddle is here

The script begins with this:

$('.drag')
    .live("click", function(){
        $( this ).toggleClass("selected");
    })
    .drag("init",function(){
        if ( $( this ).is('.selected') )
            return $('.selected');                      
    })
    .drag("start",function( ev, dd ){
        dd.attr = $( ev.target ).attr("className");
        dd.width = $( this ).width();
        dd.height = $( this ).height();
        dd.limit = $div.offset();
        dd.limit.bottom = dd.limit.top + $div.outerHeight() - $( this ).outerHeight();
        dd.limit.right = dd.limit.left + $div.outerWidth() - $( this ).outerWidth();
    })
    .drag(function( ev, dd ){
        var props = {};
        if ( dd.attr.indexOf("E") > -1 ){
            props.width = Math.round(Math.max( 32, dd.width + dd.deltaX )/ 20 ) * 20;
        }
        if ( dd.attr.indexOf("S") > -1 ){
            props.height = Math.round(Math.max( 32, dd.height + dd.deltaY )/ 20 ) * 20;
        }
        if ( dd.attr.indexOf("drag") > -1 ){
            props.top = Math.round(Math.min( dd.limit.bottom, Math.max( dd.limit.top, dd.offsetY ) )/ 20 ) * 20;
            props.left = Math.round(Math.min( dd.limit.right, Math.max( dd.limit.left, dd.offsetX ) )/ 20 ) * 20;
        }
        $( this ).css( props );
});

it might look complicated but but all it does is makes some draggable divs hor this htnl:

<input type="button" id="add" value="Add a Box" />
<div class="test" id="container">


<div class="drag" style="left:100px;">
    <div class="handle SE"></div>
</div>
<div class="drag" style="left:180px;">
    <div class="handle SE"></div>
</div>

</div>

then i use a button to add some more vids:

var $div = $('#container');
var num = 1;
    $('#add').click(function(){
        $('<div class="handle SE"><div class="drag" style="left:20px;"/>')
            .text( num++ )
            .appendTo( document.body )
            .wrap('<div class="drag" style="left:20px;"/>');
    });

And the problem i have is that the newly created divs to dot inherit the already existing settings.

If i add separate code it will work with that:

$('.drag').live("drag",function( ev, dd ){
        $( this ).css({
           top:  Math.round(dd.offsetY / 20 ) * 20,
           left:  Math.round(dd.offsetX / 20 ) * 20
        });
});

but i want the newly created blocks to use the first script. So i guess the problems is that the settings are not inherited

Any ideas?
Thanks

  • 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-05-27T16:49:52+00:00Added an answer on May 27, 2026 at 4:49 pm

    You have to specifically add the script on a newly created element, or it won’t apply. Put the drag script initialization in a separate function, and call it on the new div element:

    $('#add').click(function(){
            var newDiv = $('<div class="handle SE"><div class="drag" style="left:20px;"/>')
                .text( num++ )
                .appendTo( document.body )
                .wrap('<div class="drag" style="left:20px;"/>');
              initDrag(newDiv);
        });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I'm using the ProgressBar JQuery plugin ( http://t.wits.sg/misc/jQueryProgressBar/demo.php ) to create some static
So I am using this jquery plugin to create a nice pie chart on
I have this jQuery ajax navigation tabs plugin that I created using some help
I'm using this jQuery Tooltip plugin: http://docs.jquery.com/Plugins/Tooltip I create tooltips for all links when
I have used the jQuery Qtip plugin to create some tooltips using the following
I'm using this lightweight jQuery plugin to create a rich-text editor: Batiste RTE jQuery
I am using the jQuery Sound Plugin to create some sound effects on my
I am now using jQuery tooltip plugin to create some quick reminders for users
I wanted to create simple plugin using jquery. Also suggest me standard practice while
I'm using the plugin http://bassistance.de/jquery-plugins/jquery-plugin-tooltip/ to create tooltips with JQuery but I can't created

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.