I have lists of addresses inside php files and the files are labelled by country. So in a list called uk I could have 12 list items of addresses. But on my homepage I am trying to use jQuery to calculate the values of each country and then put the value inside a div on that country map so that it indicates that uk was x addresses, usa has x addresses and so forth.
The code I have put together below works up till the .ajax and then in console.log it echos 1 single country instead of a list of countrys.
HTML
<div class="right map">
<div class="canada" data-name="Canada"></div>
<div class="usa" data-name="USA"></div>
<div class="uk" data-name="UK"></div>
<div class="ireland" data-name="Ireland"></div>
<div class="spain" data-name="Spain"></div>
<div class="portugal" data-name="Portugal"></div>
<div class="italy" data-name="Italy"></div>
<div class="australia" data-name="Australia"></div>
</div>
jQuery
$('.map div').each(function() {
$this = $(this);
country = $this.attr("class");
console.log(country);
$.ajax({
url : "/assets/inc/coe/"+country+".php",
success : function (data) {
console.log($('.map div.'+country));
$('.map div.'+country).text($(data).find('li').size());
}
});
});
php files
<ul>
<li>
<strong>Company Name</strong>
123 Fake Street<br />
Fakesville<br />
<a href="#">Link</a>
</li>
<li>
<strong>Company Name</strong>
123 Fake Street<br />
Fakesville<br />
<a href="#">Link</a>
</li>
</ul>
console.log
canada
usa
uk
ireland
spain
portugal
italy
australia
[div.australia]
[div.australia]
[div.australia]
[div.australia]
[div.australia]
[div.australia]
[div.australia]
[div.australia]