[英]jQuery CSS - don't select <img> tag inside <a> tag
I have some jQuery code which selects all <a>
tags in my site that start with "http" and adds either a generic icon or that site's favicon and works perfectly. 我有一些jQuery代码,可以在我的网站中选择所有以“ http”开头的<a>
标签,并添加通用图标或该网站的收藏夹图标,并且效果很好。 My problem is that sometimes the <a>
tag surrounds an <img>
tag, and I don't want it to select those, so how do I tell jQuery that? 我的问题是,有时<a>
标记会包围<img>
标记,而我不希望它选择那些标记,那么如何告诉jQuery? Do I somehow use :not()
? 我会以某种方式使用:not()
吗?
Here's the current jQuery code: 这是当前的jQuery代码:
$("#bodyCopy a[href^='http']").each(function() {
$(this).css({
background: "url(http://g.etfv.co/" + this.href + ") left center no-repeat",
"padding-left": "20px"
});
});
$("#bodyCopy a[href^='http']").each(function() {
if ( $(this).find("img").length < 1 ) { // Count <img> children
// Continue only if fewer than one <img> within <a>
$(this).css({
background: "url(http://g.etfv.co/" + this.href + ") left center no-repeat",
"padding-left": "20px"
});
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.