Reputation: 2222
I must target specific label
element using its for
parameter, and I must do it in a forEach
cycle, like this:
var iw_signup_tooltip = function(elements) {
elements.forEach(function(entry) {
$('<i class="icon"></i>').appendTo($('label[for=entry]'));
}
}
And then I'm calling it like this:
var elements = ['label1', 'label2'];
iw_signup_tooltip(elements);
But for some reason function fails and doesn't attach anything. But if I manually replace entry with 'label1' for example it works fine. Or even if I put label1 without ''
it will still work, so I guess there could be a bug, or am I doing something wrong?
Upvotes: 0
Views: 38
Reputation: 104785
String concatentation! You need to write the entry
variable in - it won't be picked up automatically.
$('<i class="icon"></i>').appendTo($('label[for=' + entry + ']'));
Upvotes: 3