django cart.js loop is not running Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of django cart.js loop is not running without wasting too much if your time.

The question is published on by Tutorial Guruji team.

cart.js this is not working nothing is printed in the console or some declaration is wrong answer quickly

var updateBtns = document.getElementsByClassName('update-cart')

for(var i=0 ; i<updateBtns.length ; i++)
{
    updateBtns[i].addEventListener('click',function(){
        var productId = this.dataset.product
        var action = this.dataset.action
        console.log(productId,action)

    })
}    

is there any mistake in html code

 {% for product in products %}
    {% if product.category == "Dosa" %}
    <div class="product">        
    <tr>
      <td><h5>{{ product.name }}</h5></td>
      <td><h5>{{ product.price }}</h5></td>
      <td><button data-product={{product.id}} data-action="add" class="btn btn-warning btn-add update-cart">Add to cart</button></td>
    </tr>
    </div>
    {% endif %}
    {% endfor %}

Answer

enter image description here

Seems to be working perfectly. I would suggest to please check once in incognito/Private mode. Might be a problem of cache…

We are here to answer your question about django cart.js loop is not running - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji