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](http://codepen.io/jkinney768/pen/wkmsj “http://codepen.io/jkinney768/pen/wkmsj”)

    # 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](http://codepen.io/tbwIII/pen/yfwEe “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.

*May or may not contain any actual "CSS" or "Tricks".