So I have a function data.people() which sends and http request and receives data, therefore I am using promises and this function returns a promise. After that I use the folowing chaining
data.people()
.then(function() {
....
}, function(err) {
console.error(err);
}).then(function() {
...
}, function(err) {
console.error(err);
}).then ...
So am I writing this correct, cause I can't find any documentary on this and when I attach an eventListener to one element with a given id in the third promise, it executes before the second promise is executed (where this element is changed with another with the same id) and doesn't work in the third promise (where I need it to). Here is my full code in jsfiddle.