Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript jQuery “this” Help

  • This topic is empty.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #38762
    jcoder
    Member

    The code below is for a add to cart page, now the code works fine when one item is added to the cart, it changes the input value based on the “if”condition. When a second product gets added though since it is targeting only a class “.cartQty” it not only changes the second input value but it also changes the first one. I need to figure out how to use “this” so each product input is independent.

    Any help would be great!

    Here is my Code:




    Would something like this work?




    #105331
    TheDoc
    Member

    No, your second solution won’t work. In that case $(this) doesn’t refer to anything.

    You’ll need to use some sort of .each() loop or even better create your own function that fires each time you click add to cart.

    #105332
    jcoder
    Member

    TheDoc is there a way to target class “.cartQty” and “this”? Your other suggestions I think are over my head.
    Thanks!

    #105333
    TheDoc
    Member

    I think I’d need to see how the whole page is working to advise otherwise.

Viewing 4 posts - 1 through 4 (of 4 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.