1
How do I add elements to an element that has been added inside a each ? Following example:
$.each(data.id, function(i, item) {
$( ".lado" ).prepend("<div id='tes'>" + data.id + "</div>");
if (data.id == i) {
$( "#tes" ).append("<div>" + data.id + "</div>");
}
});
The prepend works but apparently the append doesn’t work because I don’t find the id added in the prepend.
You’re right what you did, but since he generated the code, you have to work with the
$.(document)
, otherwise you won’t find the positions.– William Aparecido Brandino
@Williamaparecidobrandino, look at this fiddle and Inspecione the elements: https://jsfiddle.net/8p788u6w/1/ . As the new element is in the variable, the positions are found. That’s what I was talking about?
– Samir Braga
In this example, the
id
is the same for everyone, the result would be made up.– William Aparecido Brandino
@Williamasimiliar, is an example rsrs. I put three ids equal to
index
of the loop to show the effectiveness of theappend
. But anyway, let’s wait for the AP to return to see if it served him. If you think something is really wrong could be more specific?– Samir Braga