I want to loop thru a file which is loaded with ajax, but it won’t loop, i have tried a couple of things but I cant get it to work.
// jquery
$.ajax({
url: 'file.html',
type: "GET",
dataType: "html",
success: function(data) {
$(data).find('div').each(function(i){
alert('found')
});
},
error: function(){
alert('oeps...')
}
});
// file.html
<div>
// content goes here
</div>
<div>
// content goes here
</div>
<div>
// content goes here
</div>
...
...
You need to change
.findto.filter. This is because.findsearches thechildrendescendants of all the elements, but since your html file is just<div>s, you need to use.filterto find them.DEMO: http://jsfiddle.net/zuPVp/