Skip to content
This repository has been archived by the owner on Sep 29, 2020. It is now read-only.

Each loop #30

Closed
xzdshr opened this issue Oct 5, 2016 · 2 comments
Closed

Each loop #30

xzdshr opened this issue Oct 5, 2016 · 2 comments

Comments

@xzdshr
Copy link

xzdshr commented Oct 5, 2016

Hi!
I have same issue with foreach loop. I'm trying to replace several images but it doesn't work.
var images = document.getElementsByClassName('watermark');
for(var i=0; i<images.length; i++){
watermark([images[i].src, logo])
.image(watermark.image.lowerRight(1))
.then(function(img){
images[i].src = img.src; // Undefined images[i] here
});
}

@vmdao
Copy link

vmdao commented Oct 5, 2016

Yes, watermark is Asynchronous. if you use for() not works right.
Try .forEach()

@xzdshr
Copy link
Author

xzdshr commented Oct 5, 2016

Works perfectly! Thank you!

@xzdshr xzdshr closed this as completed Oct 5, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants