I want to make a custom element with text taken from the element "being dragged" using a helper function. My problem is that ui is undefined, so I don't know how to get a hold of the source of the drag.
$('.draggable').draggable({
helper: function(event, ui) {
var foo = $('<span style="white-space:nowrap;">DRAG TEST</span>');
return foo;
}
});
jQueryUI provides draggable() method to make any DOM element draggable. Once the element is draggable, you can move that element by clicking on it with the mouse and dragging it anywhere within the viewport.
These functions assist with common idioms encountered when performing Ajax tasks. Also in: Miscellaneous > Collection Manipulation | Forms.
You have one of these problems: Your jQuery or jQuery UI Javascript path files are wrong. Your jQuery UI does not include draggable. Your jQuery or jQuery UI Javascript files are corrupted.
The helper
function you're applying is invoked the following way:
$(o.helper.apply(this.element[0], [event]))
That means that this
refers to the .draggable
you want inside that function, for example:
$('.draggable').draggable({
helper: function(event) {
return $('<span style="white-space:nowrap;"/>')
.text($(this).text() + " helper");
}
});
You can test it out here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With