I'm trying to clone objects to a JQuery dialog.
I succeeded in moving the objects to their destination area, by using append, however that also removed my original objects. The objects also have a function which sets their style when hovered and clicked on. That function uses the id of the object to set the style, so in this case the id of the cloned objects need to be a duplicate of the original ones.
This way the original objects are moved, but not cloned:
var lv_Parts = document.getElementById("DefaultPart"); // An area where my original 'parts' are
var lv_PartArea = $('<div class="PartWnd"/>'); // The new are for the parts, which is located in a JQuery dialog
lv_PartArea.html(lv_Parts.childNodes); // Adding the childNodes of the original partarea, which are parts
lv_CalcWindow.append(lv_PartArea); // Adding the parts to the new part area in the JQuery dialog
I tried cloning them but it didn't work:
var lv_Parts = $('DefaultPart');
var lv_PartArea = $('<div class="PartWnd"/>');
lv_PartArea.append(lv_Parts.children().contents().clone());
lv_CalcWindow.append(lv_PartArea);
How can I achieve this?
EDIT
These are the setStyle functions, I also changed lv_obj to the class name. It now lights up all the objects using the class 'Part'.
function Part_setStyle(pm_col, pm_id) {
var lv_obj;
if (!pm_id) {
lv_obj = ".Part";
} else {
lv_obj = pm_id;
}
$(lv_obj).css("background-color", pm_col);
}
function Part_onHoverIn(pm_this, pm_event) {
this.setStyle("rgb(135, 206, 250)");
}
function Part_onHoverOut(pm_this, pm_event) {
if (this.Selected == false) {
this.setStyle("rgb(220, 197, 220)");
}
}
idshould be unique.class+document.getElementsByClassNameinsteadWhen I use class, with an onHover or onClick, all the objects with the same class will light up at that moment. I only need one object to be highlighted at a time.,this/$(this)targets to the current element.thisto operate only on the item causing the event.