Div Content Replication
At a book sales page (EVO), the "buy" links are at the end of the sales content — where they should be. Generally, people would read through the material before deciding to buy.
However, some people may arrive at the page ready to buy right away.
Instead of cluttering the top of the sales content with "buy" links and perhaps turning people away, a "Tap for 'buy' links" link was published.
Tapping that link replaces it with a copy of the "buy" links already published below the sales content.
The functionality was quickly implemented. And I thought you might be interested in how it's done.
In essence, the content within the div that contains "Tap for 'buy' links" is entirely replaced with the content of the "buy" links div below the sales content. The replacement is copy, not a move. The original "buy" links remain at the end of the sales content.
A live demonstration of how it works can be obtained with a tap at the EVO book sales page.
3 Parts
The three parts of this system are:
-
The source div, a div with content that is subject to copying.
Here is example code:
<div id="source-id"> Content may be copied into the destination div. </div>
The
source-id
id value of the div will be used by the JavaScript to identify where to copy content from.The content may be whatever you wish.
-
The destination div, a div with a link that, when tapped, is replaced with a copy of the content in the source div.
Here is example code:
<div id="destination-id"> <a href="javascript:CopyContentFromSourceToDestination('source-id','destination-id')"> Tap for other content </a> </div>
The
destination-id
id value of the div is used by the JavaScript to identify where to publish the content copied from from thesource-id
div.The link calls the JavaScript CopyContentFromSourceToDestination() function with the id value of the source div and the id value of the destination div.
The link text may be whatever you wish. Tapping the link causes the copying.
-
The JavaScript that does the copying.
Here is the JavaScript:
<script> function CopyContentFromSourceToDestination(from,to) { document.getElementById(to).innerHTML = document.getElementById(from).innerHTML; } </script>
There is no customization here. Put the JavaScript on the page anywhere that JavaScript can run. Immediately above the cancel
</body>
tag can work.
Installing and Testing
All 3 parts of the system need to be on the same page.
It doesn't matter where they are are, so long as they are within the BODY area of the page.
Place them on a test page and see how they work. Then, when you are satisfied, the system is available and ready for you to use as appropriate for your web pages.
(This article first appeared with an issue of the Possibilities newsletter.)
Will Bontrager