jquery select基于背景图像名称的元素 [英] jquery select element based on background image name
本文介绍了jquery select基于背景图像名称的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图选择一个具有特定背景图像的div,这是我迄今为止。不工作。任何想法我做错了什么?
var markerShadow0 = $(div [background-image ='url(\\ \\ http://www.axtsweapons.com/gmarkers/markershadowA.png\)]);
解决方案
background-image不是元素的属性,一个css样式。
你必须遍历所有div并检查css样式。
($(this).css('background-image')==='http:// $(div)。 www.axtsweapons.com/gmarkers/markershadowA.png'){
//做某事
//停止循环
返回false;
}
});
I'm trying to select a div with a certain background image this is what I have so far. Not working. Any ideas of what I'm doing wrong? I'm trying to follow the jQuery documentation.
var markerShadow0 = $("div[background-image='url(\"http://www.axtsweapons.com/gmarkers/markershadowA.png\")]");
解决方案
background-image is not an attribute of the element but a css style.
You will have to iterate all divs and check the css style.
$("div").each( function(){
if ( $(this).css('background-image') === 'http://www.axtsweapons.com/gmarkers/markershadowA.png' ) {
//do something
//stop loop
return false;
}
});
这篇关于jquery select基于背景图像名称的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文