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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:27:48+00:00 2026-06-13T04:27:48+00:00

There is a div with id parentDiv , and there are some div with

  • 0

There is a div with id parentDiv, and there are some div with class block1 in parentDiv divl

like

<div id="btn"><input name="click" type="button" value="Click" class='button" /></div>

<div id="parentDiv">
    <div class="block1" style=" width:100px; height:100px; background:orange;">I am Block1</div>
    <div class="block1" style=" width:100px; height:100px; background:orange;">I am Block1</div>
</div>

and In JQuery, div with class block1, are draggable.

$(function(){
    $('.block1').draggable({
        drag: function() {
           $('.block1').text('Drag Now!');
        },
        stop: function() {
           $('.block1').text('Stop Now!');
        }
    });
});

These div are working as aspect, but the problem is, if any new div with block1 is appended in the parentDiv by clicking on btn input like

$('#btn').on('click', 'input.button', function(){
    var $newDiv=$('<div class="block1" style=" width:100px; height:100px; background:green;">I am Block1</div>');
});

that is not draggable.

Yes, It will not work, because it was not in DOM.

We are able to define a click event on #btn div to its children input.button, and if we add new input with class button in this #btn div, all will work as aspect.

So my question is, Is there a way to make all div draggable with in a parent container parentDiv, like we can do with #btn div?

  • 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-13T04:27:50+00:00Added an answer on June 13, 2026 at 4:27 am

    You need to use the “live” function of jquery to add events and functions on future elements.

    This code is borrowed from another post (http://stackoverflow.com/questions/1805210/jquery-drag-and-drop-using-live-events)

    (function ($) {
       $.fn.liveDraggable = function (opts) {
          this.live("mouseover", function() {
             if (!$(this).data("init")) {
                $(this).data("init", true).draggable(opts);
             }
          });
          return $();
       };
    }(jQuery));
    

    Now instead of calling it like:

    $(selector).draggable({opts});
    

    …just use:

    $(selector).liveDraggable({opts})
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

there is a div with some values like this: <div id=links> <link1>||<link2>||<link3> </div> i
Hello I have some HTML that looks like this, <div id=music_interests> <ul class=interests> <li
In my webpage, there's a div with a class named Test . How can
Hay, I have some markup like this <div id=some-id> <h2><a href=#>Title</a></h2> </div> and some
i use a parent div with three child divs , <div id=parentDiv> <div id=PagerUp
I have created a div there are two childs of that div one is
How to center a div across all browsers and behind this div there should
I have a container (div) with a background image. In this div there is
I have a div of fixed length. there is anorher div of variable length.
Here is my site: http://smartpeopletalkfast.co.uk/pos/ There is a div #nav which has a fixed

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.