title: JavaScript - saving highlighted rows
body: <p>Below is script to highlight rows in html file:</p>
  
  <pre><code>$(function(){
      $('table').addClass("table table-bordered table-condensed");
      $('.table').on('click', 'tr', function(e){
          var $tr = $(this);
  
          var $table = $tr.closest('.table');
          var our_index = $($tr,$table).index();
          if (e.shiftKey) {
              var last_index = $table.data('last-index');
              if (last_index) {
                  if (last_index &lt; our_index) {
                      while(last_index &lt; our_index) {
                          $('tbody tr:eq('+(++last_index)+')', $table).click();
                      }   
                      $('tbody tr:eq('+(last_index)+')', $table).click();
                  } else {  
                      while(last_index &gt; our_index) {
                          $('tbody tr:eq('+(--last_index)+')', $table).click();
                      }
                      $('tbody tr:eq('+(last_index)+')', $table).click();
                  } 
              }
              $table.data('last-index',our_index);
          } else {
              $table.data('last-index',our_index);
          }
  
          if ($tr.hasClass('success')) {
              $tr.removeClass('success');
          } else {
              $tr.addClass('success');
          }
      });
  });
  </code></pre>
  
  <p>I'd like now to save those highlighted rows so that when someone else will open the page, rows highlighted by be will be visible and if I will highlight some cells and then refresh the page they will stay highlighted.</p>
  
  <p>Is there any simple way to achieve that?</p>
  
  <p>Thanks in advance.</p>
  
  <p>-----EDIT-----</p>
  
  <p>I was trying to do it via localStorage:</p>
  
  <pre><code>$('tr').each(function(index){
  
  if(localStorage.getItem(index)!=null){
      $(this).addClass(localStorage.getItem(index));
  }
  });
  </code></pre>
  
  <p>and part to save:</p>
  
  <pre><code>if ($tr.hasClass('success')) {
              $tr.removeClass('success');
          } else {
              $tr.addClass('success');
              $tr.localStorage.setItem(index, 'success');
          }
  </code></pre>
  
  <p>But, that's not working. What I'm doing wrong? </p>
  
  <p>Sorry if my questions are obvious, but I'm starting with web programming.</p>