You don't need to have search all <a>
element to add the icon-video
class. You can do it only with CSS
, by using CSS [attribute*=value]
Selector. It selects every element whose attribute
value contains the substring "Value"
. So:
a[style*="img.youtube.com"] {
/* This is the same as .icon-video class */
}
Example: Selects every <a>
element whose style attribute value
contains the substring "img.youtube.com"
.
.thumb-post {
display: inline-block;
width: 50px;
height: 50px;
margin: 5px;
background-size: cover;
border: 3px solid blue
}
.thumb-post[style*="img.youtube.com"] {
border: 3px solid red
}
<a class="thumb-post" href="#" style="background-image:url(https://img.youtube.com/vi/hKRUPYrAQoE/maxresdefault.jpg)"></a>
<a class="thumb-post" href="#" style="background-image:url(https://img.youtube.com/vi/hKRUPYrAQoE/maxresdefault.jpg)"></a>
<a class="thumb-post" href="#" style="background-image:url(myimage.jpg)"></a>
<a class="thumb-post" href="#" style="background-image:url(https://img.youtube.com/vi/hKRUPYrAQoE/maxresdefault.jpg)"></a>
<a class="thumb-post" href="#" style="background-image:url(https://unsplash.it/3000/3000/?random)"></a>