Question

I've managed to copy a hidden element ($("#products-area").find(".mysets-area")) by checking the state of the element, temporarily showing it and then hide it again after cloning.

But I may think there would be a better to achieve this?

var stateVisible = $("#products-area").find(".mysets-area").css("display");
if (stateVisible == 'none') {
    $("#products-area").find(".mysets-area").show();
}

$("#user-dialog .open-mysets").html($("#products-area").find(".mysets-area").clone());                

if (stateVisible == 'none') {
    $("#products-area").find(".mysets-area").hide();
}
Was it helpful?

Solution

Why not clone the element while it's hidden and show the new element?

var orig = $("#products-area").find(".mysets-area");
var cloned = $(orig).clone().show();
$("#user-dialog .open-mysets").html(cloned);

Shown in this JS Fiddle: http://jsfiddle.net/jaypeagi/qCwJA/2/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top