Change background image on page refresh


<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js" type="text/javascript"></script>

<script type="text/javascript">
var images = ['img01.jpg', 'img02.jpg', 'img03.jpg', 'img04.jpg', 'img05.jpg'];
$('#background').css({'background-image': 'url(images/' + images[Math.floor(Math.random() * images.length)] + ')'});
</script>

JQuery add/remove class on click – toggleClass()

jQuery Function

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script type="text/javascript">
    $(document).ready(function () {
        $('#menu li').on('click', function () {
            $(this).toggleClass('open');
    });
});
</script>

HTML

<ul id="menu">
  <li> <a href="#">Menu</a>
    <ul>
      <li>>a href="#">Item</a> </li>
    </ul>
  </li>
  </li>
</ul>