kiotsukete

Q: Getting ID of draggables

I'm building a drag and drop activity in an iAd (not HTML) project and trying to combine the WYSIWYG qualities of iAd with the brilliance of jQuery. I've managed to get draggable objects to drop onto and snap to droppables and to lose their draggability once they are dropped.

 

In order to track what's dropped though, I'd like to trigger a counter to increment if the ID of the dropped object is the one that's supposed to be there.

 

Here's the code on the droppable:

 

      $(function() {
        $('.droppable').droppable({
            drop: function( event, ui ) {
                ui.draggable.position( { of: $(this), my: 'center', at: 'center' } );
                $('.draggable').draggable('disable');
                if (ui.draggable.attribute.id == "#Page1-yellowcar") { // THIS IS THE BROKEN BIT
                TotalCorrect++;
                }
            }
        });
      });

 

My code for grabbing the ID of the draggable doesn't work. If I pop an alert with ui.draggable.attribute.id nothing happens, not even an undefined alert. Any idea how I can grab the ID in iAd Producer?

 

Or am I going about this all wrong?

iMac, iOS 8.2, null

Posted on Apr 14, 2015 9:32 PM

Close

Q: Getting ID of draggables

  • All replies
  • Helpful answers

  • by kiotsukete,Solvedanswer

    kiotsukete kiotsukete Apr 14, 2015 9:54 PM in response to kiotsukete
    Level 1 (20 points)
    Apr 14, 2015 9:54 PM in response to kiotsukete

    Typically, after having worked on this for ages before posting here, a few more minutes fiddling and I just answered the question myself!

     

    if (ui.draggable.attr('id') == "Page1-yellowcar")
    

     

    was what I needed. In other words, plain old jQuery.