简体   繁体   中英

How to append to a div that was just append

I want to draw multiple lines that contains infos on a product for the exemple lets say its name. I declare the variable at the beginning of my function :

I iterate through a list of product :

var productName = '<div class="productName"></div>';

for (var i = 0; i < context._model._productsList.length; i++) {
        var productLine = '<div data-id="' + i + '" class="productLine"></div>';
        $('#boardProducts').append(productLine);
        $('[data-id="' + i + '"]').append(productName);

For each product i would like to wrap product name inside the related product name div.

But if i select $('.productName').append('A name'); it'll select all div productName.

Is there a way to append in the last productName div i did append ?

$('.productName').last().append('A name');
 $('.productName:last').append('A name');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM