用 jQuery 方法替换没有 css 查询选择器
Replace not had css query selector with jQuery methods
是否可以将 $('div:not(:has(video))')
替换为 .not
和 .has
?
如果您阅读文档,您会找到问题的答案:
queries using :has() cannot take advantage of the performance boost
provided by the native DOM querySelectorAll() method. For better
performance in modern browsers, use $( "your-pure-css-selector" ).has(
selector/DOMElement ) instead.
https://api.jquery.com/has-selector/
The .not() method will end up providing you with more readable
selections than pushing complex selectors or variables into a :not()
selector filter. In most cases, it is a better choice.
这个怎么样?使用一个,但不能同时使用:
$('div').not(':has(video)')
是否可以将 $('div:not(:has(video))')
替换为 .not
和 .has
?
如果您阅读文档,您会找到问题的答案:
queries using :has() cannot take advantage of the performance boost provided by the native DOM querySelectorAll() method. For better performance in modern browsers, use $( "your-pure-css-selector" ).has( selector/DOMElement ) instead.
https://api.jquery.com/has-selector/
The .not() method will end up providing you with more readable selections than pushing complex selectors or variables into a :not() selector filter. In most cases, it is a better choice.
这个怎么样?使用一个,但不能同时使用:
$('div').not(':has(video)')