Skip to content
Advertisement

How can I get other item not just first one on click in jquery

I created like a mini shop with 4 items and now I want to change the quantity of that items and be able to add them to a cart I created when I click button + to grab my item id but why is only grabbing me first id how can I get other items id by clicking it on same class for all of them here is the code

JavaScript

Advertisement

Answer

Using var id = $(".Single_Product").attr("id"); can only return one id from the matching selectors so it always returns the first one.

You can use siblings('.qty_value') to target the associated input or closest('.Qty_Box').find('.qty_value')

Something like:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement