JSFiddle - React, Tailwind, and code Playground
HTML
<div class="download">
<a href="/echo/html/">Some text</a>
</div>
<div class="ajax">
<a href="#" id="stuff">Entirely unrelated stuff</a>
</div>
<div id="results">
Some Results!
</div>
CSS
#results {
border: 1px solid #999;
padding: 5px;
margin: 5px;
}
JavaScript
// No point really in using context here.
// This would be better, or at least more readable
var links = $(".download a");
// No need to add in the argument if you're not actually going to use it
links.each(function() {
// Doing this will get you create the jQuery object
// without having to use the DOM createElement method
var newFrame = $('<div />');
// this.href is shorter and neater
newFrame.load(this.href, {
'html': '.ajax'
}, function(response, status, xhr) {
if (status == "error") {
console.log(xhr);
}
// This is the odd part - response is a selector?
// This should loop through each anchor that are a child
// Of the element selected by the response receieved
// Using appendTo here is better than looping through
// each element and using .append() there
$(response).find("a").appendTo("#results");
// And finally of course because this is .load()
// Remember that the actual response is also
// appeneded to the element in question,
// hence the extra .ajax appearing there
});
// This occures outside of callback,
// so it's actually executed *before* the code above
$("#results").append(newFrame);
});