3
I would like to know how to check if any element has a certain background with pure Javascript (without jQuery).
With jQuery I can use this:
if( $('.icon').css('background-image') === 'url(http://i56.servimg.com/u/f56/12/05/75/97/e410.png)' ){
//do something
}
But I’m having difficulty to do it via pure Javascript. (remembering that there are several elements .icon
on the page, I would like the code to have effect only if it has that specific background...)
Just to complement:
querySelectorAll
works only from IE8 (as documented by the MDN) andgetComputedStyle
only from IE9 onwards (MDN documentation).– dang