Kys*_*lox 5 javascript jquery jquery-selectors
我正在跟踪此示例并输入$( "div:contains('John')" ).css( "text-decoration", "underline" );,但出现异常:
VM23376:1未捕获的DOMException:无法在'CommandLineAPI'上执行'$':'div:contains('John')'不是有效的选择器。
解决方法: 改为按文本手动过滤元素:
$('div').filter(function(element){
return $(element).text().includes('John')
}).css('text-decoration', 'underline' )
Run Code Online (Sandbox Code Playgroud)