I want to be able to only toggle a class for the closest span element. What is the correct syntax? I’m a bit fuzzy still on the use of this
in event-listener functions.
First, you need to put some elements in your index.html file. You are referencing non-existent elements at this point. Explain what you think you are trying to do with the jQuery code you have written so far.
I was just using repl.it to show the snippet of JS.
This is the full project I’m working on:
Basically, I want to be able to only toggle a class on the parent span element of the ‘check’ button that is being toggled.
$(this).closest('li').toggleClass('shopping-item__checked');
1 Like
Thanks for the help. It got me going in the right direction. The solution you gave was dashing-through both the list item title and the check button, but I found the solution to only check through the list item:
Yes, I noticed the dash after I posted it. Glad you figured it out.