jQuery move element to another parent
Using jQuery .detach() function to remove the item from its original position and .append() to insert it back in the page. Actually you would not even need detach() since append() is geared to do this by itself if you pass it an element already on the page - however for clarity the detach call doesn't hurt.
On the HTML markup I use span to encompass the moving element.
Javascript:
if (toggleElement.hasClass("off"))
{ $("#section-streaming").collapse("hide");
var tsSettingsButton = $("#ts-over-settings").detach();
$("#ts-setting-location-recording").append(tsSettingsButton);
}
else
{ $("#section-streaming").collapse("show");
var tsSettingsButton = $("#ts-over-settings").detach();
$("#ts-setting-location-stream").append(tsSettingsButton);
}
HTML:
<span id="ts-setting-location-stream"> <button class="btn btn-gray" id="ts-over-settings" type="button">TS Settings</button> </span> (...) <span id="ts-setting-location-recording"></span>
Recent Comments