[英]Target element that has an element with certain a CSS property using Jquery
I want to target the element with class "keyimage" that have an a
with a certain background image. 我想使用具有特定背景图片的
a
类“ keyimage”来定位元素。
That's my code: 那是我的代码:
$( ".keyimage" ).has( "a[style^="background-image: url('https://example.com/wp-content/uploads/2018/02/white.jpg')"]" ).css( "display", "none" );
Any idea why it isn't working? 知道为什么它不起作用吗?
Thank you in advance 先感谢您
$( ".keyimage" ).has( "a[style^=\"background-image: url('https://example.com/wp-content/uploads/2018/02/white.jpg')\"]" ).css( "display", "none" );
--------------------------------^----------------------------------------------------------------------------------^
You need to add \\
in your string to skip quotes 您需要在字符串中添加
\\
以跳过引号
Or you can enclosed with the back-tick instead 或者您也可以用反勾号括起来
$( ".keyimage" ).has( `a[style^="background-image: url('https://example.com/wp-content/uploads/2018/02/white.jpg')"]` ).css( "display", "none" );
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.