Rich-text Reply

detach and insertbefore is not working sometime

nallak 12-28-16

detach and insertbefore is not working sometime

Hi guys, 

I have a problem with one of my test. I have the following:
$(".view-info").detach().insertBefore(".product-name");

 

The above detach works all the time, but only sometimes, the insertBefore is working. So sometimes, users dont see the item moved re-appear again. Do you know why this could be ? and how i can solve this?
example: https://www.bandist.de/korn-konzertgitarren-set-c546-4-4-natur.html

Level 2

RyanC 12-29-16
 

Re: detach and insertbefore is not working sometime

Try this:

var myObj = $(".view-info");
var parent = myObj.parent();
myObj.detach();
parent.prepend(myObj);
Ryan
------------------------------------------------
The best solution is the simplest.
Level 10
nallak 12-29-16
 

Re: detach and insertbefore is not working sometime

This works. But with a delay and flash. So what is the problem that you've seen to be fixed here?
Level 2
RyanC 12-29-16
 

Re: detach and insertbefore is not working sometime

This should help you have the code run immediately on load: https://help.optimizely.com/Build_Campaigns_and_Experiments/Force_variation_code_or_Experiment_JavaS...
Ryan
------------------------------------------------
The best solution is the simplest.
Level 10
nallak 12-29-16
 

Re: detach and insertbefore is not working sometime

Thanks Ryan. I'll try that now.
Level 2
nallak 12-29-16
 

Re: detach and insertbefore is not working sometime

The current solution is like this now in live:
https://www.bandist.de/green-guitars-st-special-edition-2016-blue-transparen.html

i would still like to optimise it in a way that the detach and insertBefore happens same time as the load. Any suggestion Ryan?
Level 2
RyanC 12-29-16
 

Re: detach and insertbefore is not working sometime

I can't quiet understand why you want it to happen on load. However if it is because the element is created dynamically you might want to try creating a setinterval function of 50ms to check if the element is visible and if so do any further logic.

Ryan
------------------------------------------------
The best solution is the simplest.
Level 10