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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:38:43+00:00 2026-05-23T20:38:43+00:00

i have created the drag and drop work. Here i can place the drag

  • 0

i have created the drag and drop work. Here i can place the drag content into particular area, but i have create each droppable function for draggable item. i need to simplify that.

$(document).ready(function() {          
    $(".list").draggable({
    helper: 'clone', 
    cursor: 'hand', 
    revert: true,
    drag: function(ev, ui) {    
        dragId = $(this).attr('id');
     }   
    }); 

    $("#td1").droppable({
      accept: '#1',
      activeClass: 'drop-active',
      hoverClass: 'dropareahover',
      drop: function(event, ui) {
        var targetId = $(this).attr("id");
        $("#" + targetId).each(function() {         
            $(this).append(ui.draggable.text());
        });        
      }
    });

    $("#td2").droppable({
      accept: '#1',
      activeClass: 'drop-active',
      hoverClass: 'dropareahover',
      drop: function(event, ui) {
        var targetId = $(this).attr("id");
        $("#" + targetId).each(function() {         
            $(this).append(ui.draggable.text());
        });        
      }
    });

    $("#td3").droppable({
      accept: '#2',
      activeClass: 'drop-active',
      hoverClass: 'dropareahover',
      drop: function(event, ui) {
        var targetId = $(this).attr("id");
        $("#" + targetId).each(function() {         
            $(this).append(ui.draggable.text());
        });        
      }
    });

    $("#td4").droppable({
      accept: '#2',
      activeClass: 'drop-active',
      hoverClass: 'dropareahover',
      drop: function(event, ui) {
        var targetId = $(this).attr("id");
        $("#" + targetId).each(function() {         
            $(this).append(ui.draggable.text());
        });        
      }
    });

    $("#td5").droppable({
      accept: '#3',
      activeClass: 'drop-active',
      hoverClass: 'dropareahover',
      drop: function(event, ui) {
        var targetId = $(this).attr("id");
        $("#" + targetId).each(function() {         
            $(this).append(ui.draggable.text());
        });        
      }
    });

    $("#td6").droppable({
      accept: '#3',
      activeClass: 'drop-active',
      hoverClass: 'dropareahover',
      drop: function(event, ui) {
        var targetId = $(this).attr("id");
        $("#" + targetId).each(function() {         
            $(this).append(ui.draggable.text());
        });        
      }
    });

    $("#td7").droppable({
      accept: '#4',
      activeClass: 'drop-active',
      hoverClass: 'dropareahover',
      drop: function(event, ui) {
        var targetId = $(this).attr("id");
        $("#" + targetId).each(function() {         
            $(this).append(ui.draggable.text());
        });        
      }
    });

    $("#td8").droppable({
      accept: '#4',
      activeClass: 'drop-active',
      hoverClass: 'dropareahover',
      drop: function(event, ui) {
        var targetId = $(this).attr("id");
        $("#" + targetId).each(function() {         
            $(this).append(ui.draggable.text());
        });        
      }
    });

 }); 

This is my work: http://jsfiddle.net/thilakar/u7TnA/

Please help me out.

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-23T20:38:43+00:00Added an answer on May 23, 2026 at 8:38 pm

    You can define a function like below. Look at demo here.

    function drop(selector, a) {
       $(selector).droppable({
          accept: a,
          activeClass: 'drop-active',
          hoverClass: 'dropareahover',
          drop: function(event, ui) {
            var targetId = $(this).attr("id");
            $("#" + targetId).each(function() {             
                $(this).append(ui.draggable.text());
            });        
          }
        });    
    }
    
    $(document).ready(function() {            
        $(".list").draggable({
        helper: 'clone', 
        cursor: 'hand', 
        revert: true,
        drag: function(ev, ui) {    
            dragId = $(this).attr('id');
         }     
        });    
    
        drop("#td1", '#1');
        drop("#td2", '#1');
        drop("#td3", '#2');
        drop("#td4", '#2');
        drop("#td5", '#3');
        drop("#td6", '#3');
        drop("#td7", '#4');
        drop("#td8", '#4');
     });      
    

    EDIT
    More compact sultion using arrays below. Live deme here.

    function drop2(teacher, subjects) {
        $.each(subjects, function(index, subject) {
           $(subject).droppable({
              accept: teacher,
              activeClass: 'drop-active',
              hoverClass: 'dropareahover',
              drop: function(event, ui) {
                var targetId = $(this).attr("id");
                $("#" + targetId).each(function() {             
                    $(this).append(ui.draggable.text());
                });        
              }
            });                
        });
    }
    
    $(document).ready(function() {            
        $(".list").draggable({
        helper: 'clone', 
        cursor: 'hand', 
        revert: true,
        drag: function(ev, ui) {    
            dragId = $(this).attr('id');
         }     
        });    
    
        drop2('#1',['#td1', '#td2']);
        drop2('#2',['#td3', '#td4']);
        drop2('#3',['#td5', '#td6']);
        drop2('#4',['#td7', '#td8']);    
    
     });      
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a UITextview in my Screen,I created textview in drag and drop on
I've created a subclass of NSBox to implement drag and drop. I have the
I have an exe that I can drag and drop another file onto to
I've just started learning javascript and have created a drag and drop using jquery
I have created a table using mootools sortables to implement drag and drop functionality.
I have been working with Raphael to create drag and drop shapes on a
I have created a nested list with drag/drop functionality. My issue is that I
I have created like a design studio and it has different functionalities like drag
I have created a mac application using the WebView. But issue is that webView
I have created a facebook apps. It works fine for me. But my problem

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.