Background: I'm running A/B tests for a website via VWO. I can write a script that is run when the page loads, but I cannot access any of the website's preexisting scripts or alter their code in any way besides "overwriting" in JS (e.g. remove divs, change CSS properties, append divs) after their page loads.
Problem: When the page loads, there is an empty <div id="priceinfo"></div>
. Elsewhere on the page, there is an <a href="javascript:RequestPriceInfo()" id="requestPrice"><img ...></a>
. Inside RequestPriceInfo()
, the function outputs HTML to div#priceinfo
based on certain form field values on the page. It also appends an "order" button (which is actually not a button at all, but an image nested in anchor tags). I'm trying to change the source for the "button" image using JQuery's attr()
function.
Progress: None. I have tried using $('a#requestPrice').click(function() {...} );
but it is not working to change the source of the image, I presume because the content has not yet loaded onto the page immediately when a#requestPrice
is clicked and my function runs. I need a way to tell when RequestPriceInfo()
has been fired and completed, but there is no callback parameter on RequestPriceInfo()
and I don't have access to the script to alter it and add one.
Potentially Useful Info: There is a variable, priceRequested
, which is changed from false to true when RequestPriceInfo()
runs. Though I realize nothing about this solution is going to be elegant, it seems unreasonable to use Object.prototype.watch()
to monitor the variable, but I'm running out of ideas.
How can I detect when RequestPriceInfo()
has completed to execute my function without editing the function to add a callback parameter?