jQuery .text() not retreiving element text

  Kiến thức lập trình

I have this HTML and the text is generated dynamically:

<span class="amount">1790.00</span>

My problem is I can’t retrieve the text of the span tag. Here’s my jQuery code:

$(document).ready(function() {
    displayTotalAmount();

    function displayTotalAmount() {
        let quantity = $('#quantity').val();
        console.log('quantity:', quantity);
        /* This should log '1790.22' to the console */
        console.log("Amount: " + $(".amount").text()); 
    }
}

Browser’s output:
enter image description here

2

LEAVE A COMMENT