title: jQuery/Javascript if contains else do nothing
body: <p>This function below adds the name of the student as a link to a div called 'output' when a button is pressed. </p>
  
  <pre><code>function getFavourite()
  {
  {
   name = 'Student 1 '
    $('#output').html('&lt;a href=' + window.location.href + '?student=' + '&gt;' + name + '&lt;/a&gt;'+ ', ' + ($("#output").html()));
  }
  
  
  saveFavourites();
  loadFavourites();
  $("#favourites").show();
  }
  </code></pre>
  
  <p>I'm trying to create more functionality where if the student's name is already in the div then when then the button is pressed the name is not added again and display an alert notifying the user.</p>
  
  <pre><code>function getFavourite()
  {
  if ($( "#output:not:contains('Student 1, ')" ))
      {(name = 'Student 1 ')
    $('#output').html('&lt;a href=' + window.location.href + '?student=' + '&gt;' + name +    a&gt;'+ ', ' + ($("#output").html()));
          $("#favourites").show();
      }
  else
  {return null + alert("Already added to favourites")}
  
  
  saveFavourites();
  loadFavourites();
  
  }
  </code></pre>
  
  <p>I've tried a lot of variations of the code above but with no luck.
  thanks.</p>