Hi Everyone. I'm working on a project that needs to extract links from external pages that are created with simplehtmldom and a cron job.

The problem I'm having is loading these files into my page using jQuery. The link's 'href' seems to be incorrect and I can't find a solution. It seems that with each link it add's on a href from another link, then the next will add on 2 hrefs. Anyway, here's the code:
Code JavaScript:
<script type="text/javascript"> 
 
var domain1 = "http://domain1.com/";
var domain2 = "http://domain2.com/";
var domain3 = "http://domain3.com/";
var domain4 = "http://domain4.com/";
var domain5 = "http://domain5.com/";
$("document").ready(function()  {
	if ($(window).width() > 960) {
		$("#content ul li").load("link_extract1.html a",{},function(){
			$("a").each(function (i) {  
				$(this).text($(this).text().substring(0,40));
				var  domain1_href = $(this).attr('href');  
				var new_domain1_href = domain1 + domain1_href;  
				$(this).attr('href',new_domain1_href);
			});
			$("a").append('...');    	
		}); 
		$("#content2 ul li").load("link_extract2.html a",{},function(){
			$("a").each(function (i) {
				$(this).text($(this).text().substring(0,40));
				var  domain2_href = $(this).attr('href');  
				var new_domain2_href = domain2 + domain2_href;  
				$(this).attr('href',new_domain2_href);
			});
			$("a").append('...');
		});
		$("#content3 ul li").load("link_extract3.html a",{},function(){
			$("a").each(function (i) {
				$(this).text($(this).text().substring(0,40));
				var  domain3_href = $(this).attr('href');  
				var new_domain3_href = domain3 + domain3_href;  
				$(this).attr('href',new_domain3_href);
			});
			$("a").append('...');
		});
		$("#content4 ul li").load("link_extract4.html a",{},function(){
			$("a").each(function (i) {
				$(this).text($(this).text().substring(0,40));
				var  domain4_href = $(this).attr('href');  
				var new_domain4_href = domain4 + domain4_href;  
				$(this).attr('href',new_domain4_href);
			});
			$("a").append('...');
		});
		$("#content5 ul li").load("link_extract5.html a",{},function(){
			$("a").each(function (i) {
				$(this).text($(this).text().substring(0,40));
				var  domain5_href = $(this).attr('href');  
				var new_domain5_href = domain5 + domain5_href;  
				$(this).attr('href',new_domain5_href);
			});
			$("a").append('...');
		});
	};
});  
 
</script>
The href in each link_extract file is structured like so: <a href="../topic/4365747419">Link Here</a> -> Which in turn I'd like to appear like <a href="http://domain5.com/topic/4365747419">Link Here</a>

So you can see how the href is loaded into the <a> for each item. But it appears to be tacking on links from the other files as well. I'm sure it's a simple answer but I can't see it. This is one of my first projects using jQuery.

I'd also like to know how I can only load the first 5 or so links from each external file.

Appreciate your time and help.