select background-image of div value with jquery
I'm trying to get the css value of the background-image of some div, but i don't know how.
I know that i can have all the style using the method attribute
$(document).ready(initialize);
var imageAux;
function initialize() {
$(".imagePanel").click(function () {
var aux = $(this);
if (imageSelected != aux) {
if (imageSelected != null) {
imageSelected.stop(true, true).data('selected', false);
imageSelected.css('border', '0 none');
imageSelected.css('opacity', '1');
}
aux.css('border开发者_开发知识库', '2px solid black').data('selected', true);
imageSelected = aux;
//pass the value to me aux variable
imageAux = imageSelected;
}
});
function manageAccordion() {
var imagePath = imageAux.attr("style");
}
I tried something like this but it doesn't work
imageAux.attr("style").find('background-image')
imageAux.attr("style background image"
i need a selector that give's me the background image of the div that i already have save in my variable imageAux
Use the jQuery.css function
imageAux.css('background-image');
When using .attr()
you may have multiple values in the requested attribute. For example, if you have the following div, you will have multiple class names (in this case, 'class1 class2'):
<div class="class1 class2"></div>
If you are looking for a specific CSS value, use the jQuery.css method.
精彩评论