Reputation: 13
I've used the following on a website's product page to generate a mailto: link with that product's name, and insert the div into an existing div for the product description
var $emailsubject = $("h1.ProductItem-details-title").html();
var $infoEmail = $("<div><a href='mailto:[email protected]?subject=RE: Prop Enquiry - "+$emailsubject+"'>Click here to enquire</a></div>");
$("*[data-content-field='excerpt']").append ($infoEmail);
However, I'm finding that the code doesn't run on page load, and needs to be refreshed to work. I don't know if this is because it can't load the DOM information to make the link or what is going on
I've tried document.ready and pageinit or pagecreate but it doesn't seem to want to run until the information has already been loaded fully.
Is there a way to either have this run while the page is loading or trigger a single refresh so the visitor doesn't see the lapse in information?
ETA: example page here
This is through SquareSpace so I don't have much editing power with the html structure
ETA2: I've found the problem, it was an ajax loader setting. Just needed to be turned off
Upvotes: 0
Views: 61
Reputation: 9
There is no need to use $()
for $infoEmail variable
so try below concept
var $emailsubject = $("h1.ProductItem-details-title").html();
var $infoEmail ="<div><a href='mailto:[email protected]?subject=RE: Prop Enquiry - "+$emailsubject+"'>Click here to enquire</a></div>";
$("*[data-content-field='excerpt']").append ($infoEmail);
Upvotes: 1