Reputation: 2425
Environment
What i want
Copy the box but delete the class "hure" from the copied child
Structure of the box to be cloned
<div name="box">
<a .../>
<span..../>
<span..../>
<div class="eye"> <img class="hure"..../></div>
...
</div>
2Consider
My approach:
Resulting that both class get removed, whytf not only the clone?
helper : function(ev,el) {
if ($(this).find(".hure").length > 0){
return($(el).find(".hure").removeClass("hure").clone());}
else
{
return($(this).clone());}
},
Thanks for any help, i am lost since hours trying to do that thing. I can't find code to differ the original from the ***g clone.
EDIT
An alternative way would be to do that AFTER the clone, i already tried that without success.
my successless approach
if ($(this).find(".hure").length > 0){ $(this).find(".hure").eq(1).removeClass("hure");}
Solution
stop: function() {
if ($(".hure").length>0){
$(".hure:eq(1)").removeClass("hure");}
}
Upvotes: 3
Views: 3517
Reputation: 82287
I came up with this workaround. Basically, once the drag movement stops there is an event that you can tie into. When you clone the element in the stop event, you can place it as you wish. It is at this point you should manipulate the clone. In the demo, its class "hure" is removed, and it is placed in the body. Placement can be determined here to be elsewhere.
$('.box').draggable({
helper: 'clone',
stop: function(ev,ui){
//clone helper
var copy = $(this).clone();
//use exposed api to set position
copy.position(ui.position);
copy.offset(ui.offset);
//search for the class in copy and remove it
$(".hure",copy).removeClass("hure");
//place element (this may affect position/offset)
document.body.appendChild(copy[0]);
}
});
Upvotes: 3
Reputation: 27012
Give this a try.. clone first, then remove the class on the clone:
function (ev, el) {
var $cloned = $(this).clone();
$cloned.find(".hure").removeClass("hure");
return $cloned;
}
Upvotes: 0