3 ms·
"This is what you mean by CSS-in-JS, right?" But seriously, those selectors are making me cringe. Does it even work with the spaces? $('[id="Fish & Chips"]'
by lcnPylGDnU4H9OF 3y ago
"This is what you mean by CSS-in-JS, right?"
But seriously, those selectors are making me cringe. Does it even work with the spaces?
$('[id="Fish & Chips"]')
$('[class="Fish & Chips"]')
- throwaway4233 3y agowith attribute selectors like what you have mentioned it would work. But `$('#Fish & Chips')` most certainly will not, since jQuery would throw a syntax error.
- lcnPylGDnU4H9OF 3y agoIt makes sense to throw a syntax error but I wasn't sure what the actual behavior would be. Made me wonder if jquery did some magic to understand what is being queried.
- DaiPlusPlus 3y agojQuery first came-out long before browsers had querySelector: it used a 100% JS reimplementation of a CSS selector parser and evaluator, which was eventually spun-off into its own library: Sizzle.js: https://github.com/jquery/sizzle https://github.com/jquery/sizzle - Surprisingly, jQuery didn't fully remove Sizzle until 2019 ( https://blog.jquery.com/2019/04/10/jquery-3-4-0-released/ https://blog.jquery.com/2019/04/10/jquery-3-4-0-released/ ) - if that seems surprisingly recent, don't forget that querySelector wasn't added to the DOM API until 2013 - with only IE11 supporting it: some places were still using even IE6 well past then, so it makes sense for jQuery to support it for so long. So using newer CSS selector features, like attribute value selectors, will work fine in post-Sizzle jQuery versions.