Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I ordered some code...and for me it worked</p> <pre><code>// global variables var cardsInDeck = [], numberOfCardsInDeck = 5; cardsInDeck[0] = "Ace"; cardsInDeck[1] = "Grace"; cardsInDeck[2] = "Susan"; cardsInDeck[3] = "Ian"; cardsInDeck[4] = "Barbara"; cardsInDeck[5] = "Brigadier"; cardsInDeck[6] = "Romana I"; cardsInDeck[7] = "K9"; cardsInDeck[8] = "Tegan"; cardsInDeck[9] = "Jamie"; cardsInDeck[10] = "Sarah Jane"; cardsInDeck[11] = "Jo"; cardsInDeck[12] = "Romana II"; cardsInDeck[13] = "Yates"; cardsInDeck[14] = "Leela"; //load "init" when document it's ready $(document).on('ready',init); function init() { $( "#draggable" ).draggable({ containment: "#left"}); $('.drop').droppable( {drop: handleDropEvent}); } $('#deal').click(function () { dealAll(); }); $('#reset-pictures').click(function(){ $('img.drag').remove(); numberOfCardsInDeck = 5; }); // deal 5 cards at once - works function dealAll(){ // 5 cards max, no repeat cards while(numberOfCardsInDeck){ var rand = randomCard(); dealCard(rand); } } //deal cards - works function dealCard(i) { //create id, remove space id var id_picture = (cardsInDeck[i] +'-'+i).replace(/\s/g, ''); //validate not exist image if (!!$('img#'+id_picture).length) { return; } var $img = $('&lt;img/&gt;', { src : "http://debsiepalmer.com/images/companions/" + cardsInDeck[i] + ".jpg", id : id_picture, class : 'drag', 'data-info': cardsInDeck[i] }) $('body').append($img); $('img.drag').draggable(); numberOfCardsInDeck--; } // deal randomly - works function randomCard() { return Math.floor(Math.random() * cardsInDeck.length); } // this is what to do when card drops in tardis function handleDropEvent( event, ui ) { alert(ui.draggable.attr("data-info")); } </code></pre> <p><strong>DEMO</strong></p> <p><a href="http://jsfiddle.net/johan_16/WnFkH/" rel="nofollow">JSFinddle</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload