JQuery Background Image Selector

Is there a way to identify the selector using a special background image. Is there any way to do this?

<ul style="background-image:url(/test/test/shortcutsMenu-test.png);">

I know this is the wrong way to do this, but I am manipulating a website for a mobile version of the same site.

+5
source share
3 answers

You can use filter:

$("ul").filter(function() {
    return $(this).css("background-image") === "url(/test/test/shortcutsMenu-test.png)"; 
});

This will allow you to select elements ulthat have a background image defined elsewhere, not just inline. Here is a working example .

If you do not care, and the background image will always be applied inline in the attribute style, you can use the attribute selector with the attribute style.

( )

, JavaScript, indexOf ( jQuery css ):

$("ul").filter(function() {
    return $(this).css("background-image").indexOf("findThisString") > -1; 
});
+9

:

$('ul[style*="/test/test/shortcutsMenu-test.png"]')

JSFiddle

0

You probably want the Word selector in the attribute: http://api.jquery.com/attribute-contains-word-selector/

$('[style~="/test/test/shortcutsMenu-test.png"]').get();

Strike> Edit: This is wrong. The Contains attribute should be used in this case, since it will correspond to substrings, and not in simple words:

$('[style*="/test/test/shortcutsMenu-test.png"]').get();
0
source

All Articles