Help to interpret a piece of jquery used in a templating language (liquid)

Hi all,

I am trying to debug a piece of template (liquid language).

Could someone explain what this jquery does please?

jQuery('.swatch[data-option-index="{{ option_index }}"] .{{ value | handle }}').removeClass('soldout').addClass('available').find(':radio').removeAttr('disabled');

I suspect it replaces, in the html (before it is rendered) the class "soldout" with the class "available"...and makes a radio button enabled...is that right?

Cheers,
   Colin
LVL 3
colinspursAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RobOwner (Aidellio)Commented:
Are you using angular.js by any chance as well?  As those {{ ... }} are a component of angular.

Assuming it is, angular keeps track of those variables {{option_index}} and {{value | handle}}.  When those values change, the jQuery is called.

When the jQuery is called is finds the .swatch element with the data-option-index attribute that is equal to the current value of the Angular variable {{option_index}}.  {{value | handle}} must return another class name such that the selector is updated to the following when option_index = 5 and value|handle returns "myclass"

.swatch[data-option-index=5].myclass

Once that element is found, the class soldout is removed and the class available is added.  The script then searches for a radio button within that elements children and removes the disabled attribute.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
colinspursAuthor Commented:
Thanks for the prompt reply.  Tbh I don't think (!) I'm using angular, but I am sure it's of the same family and does the same kind of thing.

I had no idea jquery was so powerful, and even more so coupled with this stuff!

I am trying to put together a Shopify site, which uses its own templating language called Liquid.  This is part of an unsupported enhancement which doesn't seem to work, so I am having to try to debug it myself.

The jquery is called when there is stock to be sold:
{% if variant.available %}...

I am sure that this bit is working OK so I'll turn my attention elsewhere.

Cheers again.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
jQuery

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.