javascript - if statement not working as it should -


I have a webshop and with jquery I have to find out that when someone is present in the cart, then a product has to be added , Then it should increase the amount

if ($ (". Store-purchase-list Ent ('Part')! = Sale NO)

If this is true , Then it should add a new row if its false should add this amount to the SalesNO product ID

It only works for the first product in Gart, then it is just a I think the line keeps adding if the statement only checks for "store-purchase-list-volume-plus", even if they are more than one of the DOM.

How to change the statement it checks everything. After store-purchase-list-volume-plus "(atr = sales)

This

.attr () method returns the attribute value only << / p>

first Elements for each set To get -Separate values, creating a looping, such as .each () or .map () method.

There is a number of looping structures available in jQuery, although your special requirement is given - find out that any element that has a specific attribute value in the set of matching elements - Using .filter () is probably the best option.

  var partExists = $ (".stor e-shopping-list-volume-plus"). Filter (function () {Return $ (this) .attr ('part') == Celso;}). Length & gt; 0; // It has an attribute with a fraction that matches the sales node, if (partExists) {// increase volume} and {// add new entry}  
< / Html>

Comments