- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
Removing a DOM element with jQuery not working!

Removing a DOM element with jQuery not working!
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report
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!
Solved! Go to Solution.
Re: Removing a DOM element with jQuery not working!
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report
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
Michael




Re: Removing a DOM element with jQuery not working!
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report
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!
Re: Removing a DOM element with jQuery not working!
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report
One more thing, when I Preview this experiement, the variation does NOT differ from the original. Something is definitely not working.

Re: Removing a DOM element with jQuery not working!
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report
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(); });
Analytics and Testing Guru




Re: Removing a DOM element with jQuery not working!
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report
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.