Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to print out the final selector in a jQuery method chain

If I have the following jQuery chain

 let mpath = $('.wlc2022.confirm').find('.something');

how can I print out ".something" or "something" (in either jQuery or raw JavaScript syntax) to the console window because its the last selector that mpath is looking for?

I have tried…

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

console.log(mpath.val)
console.log(mpath.value)

But nothing so far…

>Solution :

There is no API for that in modern (post-3.0) versions of jQuery. There used to be a .selector property on jQuery objects, but it was removed because it was unreliable.

Note also that mpath itself is not "looking for" anything; it gets the result of the jQuery-based expression. Probably the best way to do what you want would be to construct some sort of utility around that expression pattern, and have it retain that last selector and make it available somehow.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading