jQuery .css() and Dynamic Background Images
I’ve just spent several hours trying to debug a nasty issue I was having with some simple jQuery. Using SharePoint 2010’s REST api and jQuery.
Setting properties using the .css() function in jQuery’s API is actually pretty easy: $(‘#element’).css(‘property’,’value’);
Should do it.
Setting the background image property is a little different, but not terribly hard either - you simply need to remember to wrap your image path in the url() function, which is a CSS construct.
$('#element').css('background-image','url(my/path/value.png)');
There’s quite a few articles online on this, so when my background images weren’t loading, I played around with this syntax for quite some time trying to get it all to work.
Well, as it turns out, my problem was something else.
My Scenario: Using SharePoint 2010’s REST Api for lists, I am pulling everything from an Image Library called “Front Page Images” hosted on my site. Then, using the .css() function, I want to set the background image of a div for each image in the library.
The big catch was that the image library’s name had spaces in it! As it works out, something in the jQuery/javascript/CSS stack is pretty picky about spaces in urls. Poking around with the div’s background image property in Firebug a bit showed me that replacing the spaces in the path with “%20” (the url escape character sequence for space) resulted in the image appearing!
The Solution in the end was to use JavaScript’s native encodeURI() function on the image path before setting the css with jQuery. Like so:
var path=encodeURI('my/path/value.png');
$('#element').css('background-image','url(' + path + ')');
Et Voila! Now I can stop pulling my hair out.

Initial Design Concept
Framed for presentation
With color guide added for branding
A revised stab at it, with a gap between the running man logo and the text
Icon design for app launching







This is the one she liked the most, by the way.


