Adding items to cart

by this command let prod_id=id.getAttribute(‘value’);

Sir on trying the above method the problem i am facing is that the each function is not working for those elements which are created in append() function


see this one its not working console shows only ‘here’ and not i

You need to run this code after the for loop also. Write the same code after line 21.

what for loop and why after 21 and will the way i told you above work??

After the for loop, there are new elements in the DOM, which are not registered for click events. Thus, you need to update the new items for click events. So you run the same code to register all of them again.

Can you tell what code to run again not getting you here and will that method work which I sent above

The one i just mentioned above.

Your method might work, cannot confirm it. You can try, but the one i told seems better.

You did not mention any code above just sent that room this code and there was no code and themethod you told there is just this problem that when we press that button how will we fetch the info about the product then coz in past request we have to pass object with orifice info and we don’t have any info

This is the code I am talking of. And regarding the fetch request, you wanted to add the item to the cart, right? So obviously you will make a post request to the server, stating that this product is added by user. The product identification is already done by using the id variable.

Ok but that is what I am asking that how will access that id variable, if we use the input element hidden even then how to access that element so how will we get the Id of the product??

by providing product id as value for the button <button value="1234" ......

and how to access that value
using getattribute() function or some other method??

sir i go it thank you for your help