Note that there are some explanatory texts on larger screens.

plurals
  1. PODrag and Drop Jquery function not working in site
    primarykey
    data
    text
    <p>I'm having a problem getting my code to work when it's incororated into a live site. The fiddle works just fine, but when I include the identical code in a webpage, I can't get the function to load/work at all. </p> <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head&gt; &lt;meta content="text/html; charset=utf-8" http-equiv="Content-Type" /&gt; &lt;title&gt;Drag and Drop Assignment&lt;/title&gt; &lt;!doctype html&gt; &lt;link rel="stylesheet" href="styles/style1.css"/&gt; &lt;style&gt; .drop{ float: left; width: 350px; height: 400px; border: 3px solid blue; background-image: url("http://debsiepalmer.com/images/tardis 2.jpg"); background-repeat: no-repeat; background-size: cover; } #right{float: left; width: 350px; height: 400px; border: 3px solid red; } &lt;/style&gt; &lt;script src="draganddrop.js" &gt;&lt;/script&gt; &lt;script src="http://code.jquery.com/jquery-2.0.2.js" &gt;&lt;/script&gt; &lt;script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js" &gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; $ (init); function image(id, image1) { this.id = id; this.image1 = image1; } $('#deal').click(function () {dealAll( dealCard(randomCard())); }); $(function() { $( "#draggable" ).draggable({ containment: "#left"}); }); function init() { $('.drop').droppable( { drop: handleDropEvent } ); $("img").draggable(); } // global variables var cardsInDeck = new Array(); var numberOfCardsInDeck = 15; 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"; var cardsDealt = new Array(); function dealAll(){ var z=0; for (z=0;z&lt;5;z++) { cardsDealt[z] = new Image(z,dealCard(randomCard())); } } function dealCard(i) { if (numberOfCardsInDeck == 0) return false; var $img = new Image(); $img.src = "images/Companions/" + cardsInDeck[i] + ".jpg"; // Here I set the ID of the object $img.id=cardsInDeck[i]; $img.class='drag'; document.body.appendChild($img); $('#'+$img.id).draggable(); removeCard(i); return $img; } // deal randomly - works function randomCard() { return Math.floor(Math.random() * numberOfCardsInDeck); } function removeCard(c) { for (j=c; j &lt;= numberOfCardsInDeck - 2; j++) { cardsInDeck[j] = cardsInDeck[j+1]; } numberOfCardsInDeck--; numberOfCardsInDeck--; numberOfCardsInDeck--; } function handleDropEvent( event, ui ) { alert("Fantastic! You chose " + ui.draggable.attr("id") + " to be your companion."); // Here I want the id of the dropped object } &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;div id="container" div style="width:750px; margin:0 auto;"&gt; &lt;div id="page_content" style="left: 0px; top: 0px; width: 750px" class="auto-style8"&gt; &lt;!--Begin Assignment 10 ---&gt; &lt;div id="left" class="drop"&gt; &lt;img id="tardis" &gt;&lt;/img&gt; &lt;/div&gt; &lt;input type="button" value="Get Companions" id="deal" /&gt; &lt;div id="content" style="left: 0px; top: 0px; width: 750px"&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>It's supposed to generate 5 images, one of which can be selected to be dropped onto the target and generate an alert with the id of the image being dropped. Like I said, it works just fine in the fiddle - and the code is identical on the web page, so I don't understand what I'm doing wrong.</p> <p>fiddle: <a href="http://jsfiddle.net/reaglin/FUvT8/6/" rel="nofollow">http://jsfiddle.net/reaglin/FUvT8/6/</a></p>
    singulars
    1. This table or related slice is empty.
    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. This table or related slice is empty.
    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