我有一些jQuery代码,它选择我的网站中所有的<a>标签,以"http“开头,并添加一个通用图标或该网站的收藏图标,并完美地工作。我的问题是,有时<a>标记包含<img>标记,而我不希望它选择这些标记,那么我如何告诉jQuery呢?我是否以某种方式使用了:not()
下面是当前的jQuery代码:
$("#bodyCopy a[href^='http']").each(function() {
$(this).css({
background: "url(http://g.etfv.co/" + this.href + ") left center no-repeat",
"padding-left": "20px"
});
});发布于 2012-07-26 01:48:08
$("#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"
});
}
});https://stackoverflow.com/questions/11655569
复制相似问题