Aod Ren
Aod Ren

Reputation: 679

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 ?

Upvotes: 2

Views: 49

Answers (2)

Dmitriy
Dmitriy

Reputation: 3765

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

Upvotes: 1

isvforall
isvforall

Reputation: 8926

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

Upvotes: 2

Related Questions