选择所有的div与PNG背景图像 [英] Selecting all the divs with png background-image
本文介绍了选择所有的div与PNG背景图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在jQuery中选择所有具有 background-image:url(somepath / somename.png)的
在它们的样式中 div
s
解决方案
没有jQuery选择器,但是这可能工作: b
$ b $ $ $ $'code $('div')。each(function(){
if($(this).css('background-image' )=='url(image.png)'){
//在这里做点什么
}
});
然而,更有效的方法是确保您只有一个使用该背景的类图片,然后只需选择 $('。bgClass')
How can I select in jQuery all the div
s that have background-image: url(somepath/somename.png)
in their style?
解决方案
There isn't a jQuery selector, but this might work:
$('div').each( function() {
if ( $(this).css('background-image') == 'url("image.png")' ) {
// do something here
}
});
However, a more efficient method would be to make sure you only have a single class that uses that background image, then simply select $('.bgClass')
这篇关于选择所有的div与PNG背景图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文