Rich-text Reply

echoing dynamically generated link from different element

jeremyers 06-30-16
Accepted Solution

echoing dynamically generated link from different element

I'm looking to test the CTA button on our category page.  The page has a series of dynamically-generated product tiles that currently have an Add to Cart button, but I want to change this to a View Details button.  The product thumbnails are linked to the product detail page, so I'd like to update the Add to Cart button to use this same link.  Is this possible?

David_Orr 07-01-16
 

Re: echoing dynamically generated link from different element

Hi Jeremyers,

This is possible if you are familiar with jQuery and/or Javascript. You can write the logic in the variation code by accessing the code editor. Here is a link to our KB article for more info on how to use the code editor:

https://help.optimizely.com/Build_Experiments/The_Code_Editor_and_Variation_Code

To get you started, here is a sample code:

var dynamicLink = $("firstElement").attr("href");
$("differentElement").attr("href", dynamicLink);

The first line saves the link from the first element and the 2nd line changes the link source for the other element.
Senior Technical Support Engineer
Optimizely