I have a div with content that I generate using jQuery on one page (I'll just refer to it as Page 1) that I want to load onto Page 2:
<div id="latestNews">
<h4>Latest News</h4>
<ul>
<!--Section automatically loaded here and to homepage -->
</ul>
</div>
This Page 1 div contains a list of links to the 5 most recent articles, made using this code:
var $latestNews = $("#$latestNews ul");
var $titles = $("h3");
$titles.each( function( index, element ){
var i = index + 1;
if (i > 5) { return false; }
var text = "<li> <a href='$url'>" + $(element).text() + "</a> /li>";
$latestNews.append(text);
});
On Page 2, which is the home page, I want to load the same div (and only that div) but preserve the script attached to it as well. Otherwise, it loads the div and its content without creating the list items.
$homelines.load("http://.../Page1.php #latestEntries");
If there is any solution in Javascript/jQuery, let me know. Pages 1 and 2 are both in PHP, so if there's a PHP alternative I'm open to it as well.