Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I get an elements ID on mouseover and assign it to a variable?
    primarykey
    data
    text
    <p>I'm beginning to learn how to use jQuery and am creating a small project management app. In the app you can drag employees from a list and drop them on to the different projects to assign them to it. </p> <p>Inside each project div is a ul that I would like the employees to be appended to. The problem at the moment is I can get the employees added tot he div but they add outside the ul. I have tried setting up a variable to grab the element id from the project div and assign it to a variable. That variable would then be concatenated in the appendTo() call to add the item to the right list. This where I am having the problem. The variable keeps returning as [object Object].</p> <p>Thanks for any help in advance. Here is a link to the <a href="http://jsfiddle.net/imauld/2VU5j/9/" rel="nofollow">JSFiddle</a> aswell.</p> <p>HTML</p> <pre><code>&lt;ul class='employee-list'&gt; &lt;li class='employee'&gt;Ian&lt;/li&gt; &lt;li class='employee'&gt;Danny&lt;/li&gt; &lt;/ul&gt; &lt;div id='task-list'&gt; &lt;div id="task-1234" class='task'&gt; &lt;h3&gt;Design new email&lt;/h3&gt; &lt;ul id="task-1234-employees" class='tasked-employees'&gt;&lt;/ul&gt; &lt;/div&gt; &lt;div id ="task-4321" class='task'&gt; &lt;h3&gt;Update Cart Code&lt;/h3&gt; &lt;ul id ="task-4321-employees" class='tasked-employees'&gt;&lt;/ul&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>Jscript</p> <pre><code>$(document).ready(function () { $(function () { var $taskID = $('.task').mouseover(function() {return this.id;}); $(".employee").draggable({ revert: 'invalid' }, { snap: '.task-slot', snapMode: 'inner' }, { appendTo: 'body', helper: 'clone' }); $('.task').droppable({ activeClass: "ui-state-default", hoverClass: "ui-state-hover", accept: ":not(.ui-sortable-helper)", drop: function (event, ui) { $(this).find(".placeholder").remove(); $("&lt;li class='task-slot'&gt;&lt;/li&gt;").text(ui.draggable.text()).appendTo("#" + $taskID +"-employees"); } }); }); }); </code></pre>
    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