Rich-text Reply

Issue when using JQuery

sam132 04-22-15

Issue when using JQuery

I'm having issues when using JQuery with an experiement:

 

To begin with I went to my project settings>Javascript and enabled "Include full jQuery in project code".


I then added some HTML, CSS and Javascript to my experiment.

What should happen is when someone clicks "Please note:" or "Free Edition Limitations" text should slide out (as I created in a test at:http://jsfiddle.net/5w4rzhc1/

However it's not working on my experiement, any idea why?

Have raised a support ticket but thought it might be useful to share the answer with the community.

Always looking to connect with optimisation experts, connect at: https://uk.linkedin.com/in/samueljefferies
Level 2

JDahlinANF 04-22-15
 

Re: Issue when using JQuery

This .click() assignment will not work if the element is not on the page when the code runs.

[code]$("#expand dt a").click(function () {
   $(this).parent().siblings("dd").slideToggle();
});[/code]

 

 

Have you tried wrapping it inside a $(window).ready() ?

 

If that doesn't help, can you point us to a page on your site where this experiment could run so we can look at the exact order of execution?

sam132 04-23-15
 

Re: Issue when using JQuery

,Thanks,

 

The element is on the page. 

 

I've created a experiement with 100% traffic allocation on the new variation you can see this at:

http://www.workbooks.com/optimizley-test

 

However on the JSFiddle you can see everything working fine at: http://jsfiddle.net/5w4rzhc1/

 

Any idea why?

 

Sam

Always looking to connect with optimisation experts, connect at: https://uk.linkedin.com/in/samueljefferies
Level 2
greg 04-23-15
 

Re: Issue when using JQuery

In addition to the above, try this:

 

window.$("#expand dt a").click(function () {
    $(this).parent().siblings("dd").slideToggle();
});

Level 2
sam132 04-24-15
 

Re: Issue when using JQuery

[ Edited ]

@greg and @nap0leon

 

Is this code to be added within the Experimental Javascript as it prompted an alert stating:

 

"Error evaluating experiment javascript:
TypeError: window.$ is not a function (line 5, col 8)"

 

Line 5 being:

 

window.$("#expand dt a").click(function () {

 

By the way very cool site.

Always looking to connect with optimisation experts, connect at: https://uk.linkedin.com/in/samueljefferies
Level 2
JDahlinANF 04-27-15
 

Re: Issue when using JQuery

Did you try placing the code inside document.ready?

$(document).ready(function() {
  $("#expand dt a").click(function () {
    $(this).parent().siblings("dd").slideToggle();
  });
});