Rich-text Reply

Removing a DOM element with jQuery not working!

Skerlnik 06-21-16
Accepted Solution

Removing a DOM element with jQuery not working!

I have an experiement where the only difference between variations is that I'd like to remove the style element from the variation.  I am using the Variation Code box, with the code: $("style").remove(); 

 

For some reason, in the Optimizely editor, BOTH variations appear to have no style element (white background), yet when looking at the live site (https://shopper.fund/sf/Account/CreateAccount) the style element (orange gradient background) appears to always exist.

 

What is happening here?  Many thanks!

Level 2

CouchPsycho 06-21-16
 

Re: Removing a DOM element with jQuery not working!

Your link has a ")" at the end ;-)

 

If i execute your remove-command in the console, the style is removed. If i activate your experiment manually

optimizely.activate(6188492767);

the style is although removed. I suppose, you have an activation-issue. Have you checked that?

 

Kind regards

 

Michael




"the essence of the creative act is to see the familiar as strange." (anonymous)
Skerlnik 06-21-16
 

Re: Removing a DOM element with jQuery not working!

Whoops!  https://shopper.fund/sf/Account/CreateAccount

 

I didn't know about manual activation, that's useful.  I see the style being removed as well.

 

How would I determine if I have an activation issue?  The experiment is listed as running.

 

Thanks!

Level 2
Skerlnik 06-21-16
 

Re: Removing a DOM element with jQuery not working!

One more thing, when I Preview this experiement, the variation does NOT differ from the original.  Something is definitely not working.

Level 2
JasonDahlin 06-21-16
 

Re: Removing a DOM element with jQuery not working!

You're trying to remove all of your <style> tags?  Seems like an odd thing to do...

 

Anyway, the code runs right away and .remove()s any <style> elements it finds.  The problem is that your <style> elements do not exist yet when the Optimizely snippet runs.

 

You could force the code to wait to run until $(document).ready(), but this will cause quite a bit of "flashing"..

$(document).ready(function() {
	$("style").remove(); 
});
--Jason Dahlin
Analytics and Testing Guru Smiley Happy
Experimentation Hero
Skerlnik 06-21-16
 

Re: Removing a DOM element with jQuery not working!

Thank you!  I was under the impression that Optimizely was awaiting the ready state to execute any code in that Variation Code editor, but it appears that I still needed this.  Seems to be working now.

Level 2