Changing background-color permanently with .hover()?

Changing background-color permanently with .hover()?

I'm working on a mini-project that mimics Etch-a-sketch.  I want to change the background color of each dynamically created DIV when the mouse hovers over the element, the change must be permanent.  I've spent a couple hours trying to get the color to stick but can't get there on my own, any help will be greatly appreciated!

  1. $(document).ready(function () {
  2.     var grid = 0;

  3.     //Function to create a grid
  4.     function createGrid(g) {
  5.         for (var y = 1; y <= grid; y++) {
  6.             for (var x = 0; x <= grid; x++) {
  7.                 if (x != grid) {
  8.                     $('#grid').append('<div class="row"></div>');
  9.                 } else {
  10.                     $('#grid').append('<br><br>');
  11.                 }
  12.             }
  13.         }
  14.     }
  15.     
  16.     //Function to generate random colors
  17.     function getRandomColor() {
  18.     var letters = '0123456789ABCDEF'.split('');
  19.     var color = '#';
  20.     for (var i = 0; i < 6; i++ ) {
  21.         color += letters[Math.floor(Math.random() * 16)];
  22.     }
  23.     return color;
  24. }
  25.     
  26.     //Change color on hover
  27.     $('.row').hover(function(){
  28.         $(this).css('color', getRandomColor());
  29.     })

  30.     //Listen for click on submit
  31.     $('#submit').on('click', function (event) {
  32.         event.preventDefault();
  33.         grid = Number($('#input').val());
  34.         createGrid(grid);
  35.     })
  36. })