I'm still getting used to ES6 (not that I was an expert in ES5) and the concept of promises is kind of killing me.
(Sorry in advanced that I can't use JSFiddle from my work.)
I have an event listener that, on click, is retrieving a web page (HTML). I'm utilizing jQuery's ajax
method to do the pull. My goal is to change the style (color for now) upon looking up a value in the pulled web page.
$("a").each(function(index) {
this.addEventListener("click", function(evt) {
$.ajax(this.href)
.done(function(html) {
var int1 = parseInt($($.parseHTML(html)).find("int1").text());
if (int1 > 0) {
this.style.color = "blue"; // this 'this' doesn't refer to the anchor. It refers to the function I think
}
}
});
});
});
(I think I closed all of the brackets)
I've tried doing .then()
after the .done()
but I run into the same problem.
Is there a way to refer to anchor that initiated the ajax call from within the done
function or is there a better way to do this?