Cant target class after append

Hi,

I am having problems targeting a class from a div i have appended inside on on click function. I have posted a section of this function below. After i have appended the html should i be able to target it from this same on click function or do i need to do something different for this?

Thanks!



$(".basketButton2").on("click", function() {

   $(".basketList").append('<li class="basketListProduct2"><span class="productPrice2">0</span></li>'});

    var newProductPrice = parseFloat(oldProductPrice) + parseFloat(v['productPrice']);
    $(".productPrice2").text(newProductPrice);

});


Hi Banana Man,

You’ve got a small typo in your code… there’s a stray curly brace at the end of this line:

$(".basketList").append('<li class="basketListProduct2"><span class="productPrice2">0</span></li>'});

Thanks. For clarity I just added part of the function here and made the error during the process. Any have an idea why I’m getting this issue?

There shouldn’t be any problem in selecting a dynamically inserted element. What’s happening to the value in <span class="productPrice2">0</span> is it staying the same or being blanked or anything? Also, are you getting any errors in the browser’s console?