Please see my comment to the question. I would not use jQuery way here. The native HTML element object does in better, more maintainable manner which is also supported by Visual Studio Intellisense. Instead of two last line, I would write
img.style.backgroundColor =
Please see:
HTMLElement.style - Web APIs | MDN[
^].
Note that this style will be applied on top of the style already applied to the element. Also note that this color has nothing to do with the content of the image; you won't see any color difference if the image fully fills the
img
element, so, to see it, you either need to have semi-transparent image, or some padding inside
img
. It could be another (way too trivial) reason why you may not see the difference.
—SA