Reputation: 999
I would like to copy a div and its contents from one page and display it on another. I would like to do this so i could use the script in a CMS where an HTML editor is set.
I though about using javascript "document.getElementById" but this should be on the same page as the Div.
However I am not having any luck getting it to work.
Thanks.
Upvotes: 0
Views: 2222
Reputation: 2842
I'd do this in php by using include
.
Take the div and it's contents out of the page it's currently in and save it in it's own file, named however makes most sense given it's content. I'll use div.html
.
Now, on the original page it was cut from, wherever you cut it out, put in:
<?php
include("div.html");
?>
You can then use this code to include the div in any other php files you so wish.
Upvotes: 1
Reputation: 955
You could load the page in a hidden iframe and access it using jQuery:
div = $('#my-iframe').contents().find('div#my-div').clone();
alert($(div).html());
This will show an alert box with the HTML contents of the div inside the iframe.
Upvotes: 0