# How to console.log the innerText from elements that were removed?

**URL:** <https://forum.freecodecamp.org/t/how-to-console-log-the-innertext-from-elements-that-were-removed/316176>\
**Category:** Curriculum Help\
**Tags:** javascript\
**Created:** [September 21, 2019, 6:56pm UTC](https://forum.freecodecamp.org/t/how-to-console-log-the-innertext-from-elements-that-were-removed/316176 "2019-09-21T18:56:08Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![fkhan698](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/fkhan698/32/133991_2.png) [@fkhan698](https://forum.freecodecamp.org/u/fkhan698)\
**Post date:** [September 21, 2019, 6:56pm UTC](https://forum.freecodecamp.org/t/how-to-console-log-the-innertext-from-elements-that-were-removed/316176/1 "2019-09-21T18:56:08Z")

</div>

[Codepen](https://codepen.io/fkhan698/pen/vYBrGbr?editors=1111)

In my `updateCartTotal()` function I want to `console.log` the elements that were removed from my shopping cart.

Each time I press the remove button, I want it to print out the `item` , and `price` . However, whenever I do it it returns undefined. And in some instances it only recognizes 1 item only. I don’t think there is a problem with my JavaScript code rather it may be my HTML

```auto
const updateCartTotal = () => {
    var cartItemContainer = document.getElementsByClassName('cart-items')[0]
    var cartRows = cartItemContainer.getElementsByClassName('cart-row')

    for(var i = 0; i < cartRows.length; i++){
        var cartRow = cartRows[i];
        var itemElement= cartRow.getElementsByClassName('cart-item')[0].innerHTML
        var priceElement = cartRow.getElementsByClassName('cart-price')[0].innerHTML
        var quantityElement = cartRow.getElementsByClassName('cart-quantity-input')[0]

        var item = itemElement.innerText
        var price = priceElement.innerText
        // var quantity = quantityElement.value
        console.log(item, price)
    }
}

```

```auto
<section class="container shopping-cart">
    <div class="title">Cart</div>
    <div class="cart-row">
        <span class="cart-item cart-header cart-column">ITEM</span>
        <span class="cart-price cart-header cart-column">PRICE</span>
        <span class="cart-quantity cart-header cart-column">QUANTITY</span>
    </div>
    <div class="cart-items">
        <div class="cart-row">
            <div class="cart-item">
                <span class="cart-item-title">Item 1</span>
            </div>
            <span class="cart-price ">$14.99</span>
            <div class="cart-quantity-input">
                <input type="number" value="1">
                <button class="btn btn-danger ml-5" type="button">REMOVE</button>
            </div>
        </div>
        <div class="cart-row">
            <div class="cart-item">
                <span class="cart-item-title ">Item 2</span>
            </div>
            <span class="cart-price">$79.99</span>
            <div class="cart-quantity-input">
                <input type="number" value="2">
                <button class="btn btn-danger ml-5" type="button">REMOVE</button>
            </div>
        </div>
    </div>
</section>

```

---

<div class="post-metadata">

**Author:** ![codemamba](https://avatars.discourse-cdn.com/v4/letter/c/919ad9/32.png) [@codemamba](https://forum.freecodecamp.org/u/codemamba)\
**Post date:** [September 21, 2019, 7:56pm UTC](https://forum.freecodecamp.org/t/how-to-console-log-the-innertext-from-elements-that-were-removed/316176/2 "2019-09-21T19:56:36Z")

</div>

There’s a typo. The variable `cartItemContainer` needs to use the class ‘cart-item’ instead of ‘cart-items’.

Also, the `ready` function isn’t hoisted since it’s written using arrow functions, so you have to either re-write it using the `function` keyword or move the on-load function call at the top to below it.

---

<div class="post-metadata">

**Author:** ![fkhan698](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/fkhan698/32/133991_2.png) [@fkhan698](https://forum.freecodecamp.org/u/fkhan698)\
**Post date:** [September 22, 2019, 7:00pm UTC](https://forum.freecodecamp.org/t/how-to-console-log-the-innertext-from-elements-that-were-removed/316176/3 "2019-09-22T19:00:55Z")

</div>

I changed the `cartItemContainer` to `cart-item` but that didn’t console.log anything. With my previous code it only console.logs the items that remain in the cart instead of console.loging the item that were removed

---

<div class="post-metadata">

**Author:** ![codemamba](https://avatars.discourse-cdn.com/v4/letter/c/919ad9/32.png) [@codemamba](https://forum.freecodecamp.org/u/codemamba)\
**Post date:** [September 22, 2019, 7:11pm UTC](https://forum.freecodecamp.org/t/how-to-console-log-the-innertext-from-elements-that-were-removed/316176/4 "2019-09-22T19:11:32Z")

</div>

Hey, I re-read your question again and I made a mistake. It indeed should be `cart-item`.

Now the reason it’s only logging the items left in the cart is because the button removes the item that was clicked on before the logging.

Since the logging takes place after removing, it will only log the items still left and not include the one that was removed. If you want to log the removed item, you’ll have to write the code inside of the `removeCartItems` function.

This should work if you put it inside `removeCartItems`.

```auto
let item = buttonClicked.parentElement.parentElement.getElementsByClassName('cart-item')[0].innerText
let price = buttonClicked.parentElement.parentElement.getElementsByClassName('cart-price')[0].innerText
console.log(item, price)

```

---

<div class="post-metadata">

**Author:** ![fkhan698](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/fkhan698/32/133991_2.png) [@fkhan698](https://forum.freecodecamp.org/u/fkhan698)\
**Post date:** [September 22, 2019, 11:22pm UTC](https://forum.freecodecamp.org/t/how-to-console-log-the-innertext-from-elements-that-were-removed/316176/5 "2019-09-22T23:22:58Z")

</div>

Okay that worked for me. But console.loging was just a small piece to the puzzle in all this. I want to be able to make the price an actual number using `parseFloat()` and multiply that with the quantity value. In the end I want all of that to update the inner text of the total based off whats the price and quantity. And I was planning on using the `updateCartTotal` for all of that. I’m just lost on how I will connect all these together

---

<div class="post-metadata">

**Author:** ![codemamba](https://avatars.discourse-cdn.com/v4/letter/c/919ad9/32.png) [@codemamba](https://forum.freecodecamp.org/u/codemamba)\
**Post date:** [September 23, 2019, 1:40pm UTC](https://forum.freecodecamp.org/t/how-to-console-log-the-innertext-from-elements-that-were-removed/316176/6 "2019-09-23T13:40:19Z")

</div>

It sounds like you have a solid plan for how to do it.

After you multiply the price and quantity, you can just set the innerText of the total element to that value.

What have you tried so far and what problems are you running into?

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [January 25, 2021, 12:15pm UTC](https://forum.freecodecamp.org/t/how-to-console-log-the-innertext-from-elements-that-were-removed/316176/7 "2021-01-25T12:15:55Z")

</div>

Closed on January 25, 2021, 12:15pm UTC


