Solved

drag and drop question

Posted on 2011-09-13
7
306 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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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)

706 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now