jquery to copy an element on the page
Posted on 2016-08-03
At the bottom of each product page, there is an editable region where I can insert my own content (including code).
In this section of the page, I want a COPY of the button to appear. So I view the source code, copy this block of code:
... and paste it into the editable content region at the bottom of the page.
Doing this creates a second copy of the button.
It works fine.
The problem is, since this block of code calls a function, and the parameter of the function is the Product ID, and the product ID is different for every product ... I can't simply copy/paste this same block of code into every product page.
Instead I have to paste the code. Then view the source code, grab the product ID, then go back into my copy and update the parameter. Because the ID is unique for each product, I have to manage these codes manually.
Using jQuery, is there a way that I can just say "Find the button on this page and make a copy of it here"?
This way I am copying/pasting the same block of code for every product, and it automatically grabs the product ID without me having to manually update it?