Treehouse: Grow your CSS skills. Land your dream job.

jQuery “this” Help

  • # July 3, 2012 at 3:32 pm

    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?

    # July 3, 2012 at 3:57 pm

    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.

    # July 3, 2012 at 4:05 pm

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

    # July 3, 2012 at 4:24 pm

    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)

You must be logged in to reply to this topic.