Solved

drag and drop question

Posted on 2011-09-13
7
310 Views
Last Modified: 2012-05-12
I have tried to make my sample as basic as possible.
I have looked at all the examples i could find , but can not make this work. I have to be missing something very obvious
I have two container divs socialSidebar and content
I am trying to drag any one of the draggable divs from socialSidebar to eventContent
but for some reason only "map" is draggable

any help will be Greatly appreciated.
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js"></script>

<script type="text/javascript">
    var debugging = true; // or true
    if (typeof console == "undefined") {
        var console = { log: function() {} }; 
    }else if (!debugging || typeof console.log == "undefined"){
        console.log = function() {};
    } 

    $(document).ready(function(){  

        $( "#liveWidgets" ).sortable({
                placeholder: "ui-state-highlight"
        });
        $( "#liveWidgets" ).disableSelection();

        $( "#liveWidgets" ).sortable({
           change: function(event, ui) {
               console.log("in change");
            }
        });

        $( "#draggable" ).draggable();
        $( "#eventContent" ).droppable({
                drop: function( event, ui ) {
                    console.log("in drop");
                        $( this ).addClass( "ui-state-highlight" );
                        //         .find( "p" ).html( "Dropped!" );
                }
        });    
    });    



</script>

<style>
    #socialSidebar{
        position: absolute;
        border: 5px solid #D2E0E6;
        width: 300px;
    }
    #content{
        position: absolute;
        border: 5px solid  #FF9797;
        width: 300px;
        left: 310px;
    }
    #draggable{
        border: 1px solid red;
        width: 200px;
        margin: 10px;
        cursor: move;
    }
    #liveWidgets li{
        border: 1px solid blue;
        width: 200px;
        margin: 10px;
        cursor: move;
    }
</style>

<div id="socialSidebar">
        <div id="unWidgetsTitle">
            Available widgets
        </div>
        <div id="availableWidgets">
            <div id="draggable" class="ui-widget-content" >map</div>
            <div id="draggable" class="ui-widget-content" >countdown</div>
            <div id="draggable" class="ui-widget-content" >email</div>
        </div><!-- end of availableWidgets -->
</div><!-- end #socialSidebar -->


<div id="content">
    <div id="eventContent">
        <ul id="liveWidgets">
            <li id="w0" class="myWidget" t="comments">
                <h4 class="widgetLabel">Comments</h4>
            </li>
            <li id="w1" class="myWidget" t="text">
                <h4 class="widgetLabel">Plain Text</h4>
            </li>
        </ul>                
    </div>
</div><!-- end #content -->

Open in new window

0
Comment
Question by:paries
  • 5
  • 2
7 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 36533367
You can have the same ID for multiple element. ID must be unique in a document. So use a different ID OR a class (the same on, no problem)
check this : http://jsfiddle.net/zNraJ/2/

        <div id="draggable1" class="ui-widget-content" >map</div>
        <div id="draggable2" class="ui-widget-content" >countdown</div>
        <div id="draggable3" class="ui-widget-content" >email</div>

Open in new window


$( "#draggable1,#draggable2,#draggable3" ).draggable();

Open in new window


    #draggable1,#draggable2,#draggable3{
        border: 1px solid red;
        width: 200px;
        margin: 10px;
        cursor: move;
    }

Open in new window

0
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 36533371
using the same class (ui-widget-content) : http://jsfiddle.net/zNraJ/3/

        <div class="ui-widget-content" >map</div>
        <div class="ui-widget-content" >countdown</div>
        <div class="ui-widget-content" >email</div>

Open in new window


$( ".ui-widget-content" ).draggable();

Open in new window


    .ui-widget-content{
        border: 1px solid red;
        width: 200px;
        margin: 10px;
        cursor: move;
    }

Open in new window

0
 
LVL 82

Expert Comment

by:leakim971
ID: 36533383
http://www.w3.org/TR/html4/struct/global.html#h-7.5.2

http://www.w3schools.com/tags/att_standard_id.asp
Definition and Usage

The id attribute specifies a unique id for an HTML element (the id attribute value must be unique within the HTML document).

The id attribute can be used to point to a style in a style sheet.

The id attribute can also be used by a JavaScript (via the HTML DOM) to make changes to the HTML element with the specific id.
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

Author Comment

by:paries
ID: 36533433
leakim971:
That is why i was confused.
The jquery examples all had dup id's which did not make sense to what i knew
http://jqueryui.com/demos/droppable/ but they do have different classes
0
 
LVL 82

Expert Comment

by:leakim971
ID: 36533439
check again :)

<div class="demo">
      
<div id="draggable" class="ui-widget-content">
      <p>Drag me to my target</p>
</div>

<div id="droppable" class="ui-widget-header">
      <p>Drop here</p>
</div>

</div><!-- End demo -->
0
 

Author Comment

by:paries
ID: 36533445
ouch!!!! wow too many hours
0
 
LVL 82

Expert Comment

by:leakim971
ID: 36533459
;))
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Got endorsements from your clients?  Great!  There is almost nothing better than word-of-mouth advertising.  But how can you do that on the internet?  Sure you can make a page for endorsement quotations and list them all, but who is …
Requirements JQuery 1.6+ HTML CSS Introduction This article was inspired by an EE question (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28372511.html) on how to make a page show some balloons animate up a page…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question