Skip to content

Instantly share code, notes, and snippets.

@johnbocook
Created January 31, 2015 02:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnbocook/a19bad4dc38b4973c705 to your computer and use it in GitHub Desktop.
Save johnbocook/a19bad4dc38b4973c705 to your computer and use it in GitHub Desktop.
Gets pathname (domain.com/pathname) and add's background image of same name.
//Get Pathname and Add background image of path for dynamic backgrounds.
var loc = window.location.pathname.substring(1);
if (loc === '') {
$( "#marketing-header" ).css('background-image', 'url(/img/default-bg.jpg)');
} else {
$( "#marketing-header" ).css('background-image', 'url(/img/'+loc+'.jpg)');
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment