Get a free trial // Grow your CSS skills // Land your dream job

Random background image javascript help

  • # December 5, 2012 at 5:16 pm

    I’ve been trying to get a div to load a different background image everytime the page is loaded, but can’t get it to work at all. If anyone could help that would be greatly appreciated. Here is some code:

    [CodePen]( “”)

    # December 5, 2012 at 8:31 pm

    You have a couple of issues with your code. First of all, with codepen, you don’t need to put the javascript inside of `

    # December 5, 2012 at 10:18 pm

    It’s probably a good idea to move those image paths to CSS and just put different classes on via the JavaScript.

    Here’s an example: [codepen]( “Codepen Example”)

    # December 5, 2012 at 11:11 pm

    Thanks a lot guys. You’ve been very helpful.

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.

There's a whole bunch of content on CSS-Tricks.

Search for Stuff   •   Browse the Archives

Get the Newsletter ... or get the RSS feed