javascript - Change Div and Body Class on Refresh -


i'm using backstretch plugin apply stretched background image body element.

$("body.apples").backstretch("/apples.jpg"); $("body.oranges").backstretch("/oranges.jpg"); $("body.pears").backstretch("/pears.jpg"); 

i want body class change on refresh, shows different background images on refresh. i'm trying work out how show related .wrapper div below when page refreshed.

<body class="apples">     <div class="wrapper apples">         <h1>something apples</h1>         <p>some content</p>     </div>      <div class="wrapper oranges">         <h1>something oranges</h1>         <p>some content</p>     </div>      <div class="wrapper pears">         <h1>something pears</h1>         <p>some content</p>     </div> </body> 

i've managed .wrapper div change on refresh bit of js:

function randomfromto(from, to) {         return math.floor(math.random() * (to - + 1) + from);     }      function randomfruit() {         var r = randomfromto(1, $('.wrapper').length);         $('.wrapper').hide().eq(r - 1).show();     }      $(document).ready(function() {         randomfruit(); }); 

i've got working demo here: http://codepen.io/realph/pen/kcetb

for reason, can't work out how make background , .wrapper div change.

any appreciated. in advance.

maybe can if else statement? , need 1 wrapper

if ( $("body").hasclass("yourfruithere") ) { $(".wrapper").html("<h1>something fruit</h1><p>some content</p>"); 

Comments

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -