Add jquery ui function draggable/resizeable after appending/adding it on the page
10,199
Just restructure so you initialize the widgets after adding the element:
$('#button').click(function() {
//create an element
var $element = $('<div class="draggableResizable" />').text('some text');
//append it to the DOM
$("#pageWrap").append($element);
//make it "draggable" and "resizable"
$element.draggable().resizable();
});
Here is a demo: http://jsfiddle.net/ZSgBP/1/
Author by
King Pangilinan
knows PHP,MySQL, Ruby(Rails), JS(jquery), CSS, HTML
Updated on June 26, 2022Comments
-
King Pangilinan almost 2 years
I have problem on my webpage, I am adding an element in the document when the user clicks on a specific button.
the element is
<div class="draggableResizable"> Some text </div>
script.js
$('#button').click(function() { $("#pageWrap").append(element) }) $('.draggableResizable').draggable().resizable()
Any suggestions are welcome.
Thank you.
-
Jasper about 12 yearsYou can also make this into a one-liner if you want:
$("#pageWrap").append($('<div class="draggableResizable" />').text('some text').draggable().resizable());
-
Gino over 10 yearsFor me in your jsfiddle demo the resizable do not work