Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

drag and drop question

Posted on 2011-09-13
7
Medium Priority
?
315 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
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 code hide show and toggles. 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…
Suggested Courses

596 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