jquery function: how to get this element id?
Hi guys,
i'm trying to do a drag and drop...,practically a newbie to jquery & all
basically i have a list of draggable objects and a container(that these draggable objects can be dropped into)
all i want to do is whenever i drop one of the objects onto the container, an alert would pop, "you have dropped "item X" into the container".
i got the object moving but alerting the user seems to be a problem. anyone see what i'm doing wrong or what i'm not doin
code below
- <HTML>
- <HEAD>
- <script type="text/javascript"
- src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
- <script type="text/javascript"
- src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.js"></script>
- </HEAD>
- <BODY>
- <DIV id="fbox" class="movable" style="width:150px;height:150px;background-color:red;border:1px solid #999999"> </DIV>
- <DIV id="sbox" class="movable" style="width:150px;height:150px;background-color:red;border:1px solid #999999"> </DIV>
- <DIV id="container" style="width:150px;height:150px;background-color:blue;border:1px solid #999999"> </DIV>
- <SCRIPT TYPE="text/javascript">
- var dragObject = null; //object we can drag
- $(document).ready(function(){
- $(".movable").draggable(
- //{
- // dragObject=this;
- //}
- );
- $(".movable").draggable();
- $("#container").droppable(
- {
- drop: alertUser
- }
- );
-
- function alertUser()
- {
- alert('you dropped ' + dragObject.id); //getting undefined here
- }
-
- $( ".movable" ).bind( "drag", function(event, ui) {
- dragObject=ui;
- });
- });
- </SCRIPT>
-
- </BODY>
- </HTML>
any suggestion would be greatly appreciated