Message from JavaScript discussions

December 2018

— Lmao


Hi Guys,
Can you give me insight? how to solve duplicate element once I append element using .append() inside .each() method on jquery.

this is my trigger, I have more than div example with class same.

<div class="dfp_leaderboard"></div>
<div class="dfp_leaderboard"></div>
<div class="dfp_leaderboard"></div>

and this is my code to append element to class on above :

$('.dfp_rectangle').each(function (indexAds) {
appendTextRetangle += "<div id='WT_Homepage_Rectangle1_"+indexAds+"'>"
appendTextRetangle += "<script type='text/javascript'>"
appendTextRetangle += "googletag.cmd.push(function() { googletag.display('WT_Homepage_Rectangle1_" + indexAds + "'); });"
appendTextRetangle += "<\/script>"
appendTextRetangle += "<\/div>"


and the result of the code with red square, and for good expectation result is square black.

— Only re init the var inside the each

— Var appendTextRectangle = ''

— And solve

— I see, Thanks for help.

— Go for tree.js or choose another library? Context: sport shoes configurator

— Just don't do p5.js

— Lol

— Why?

— Because it's terrible

— Dont think so... easy for beginners