What am i doing wrong? (inArray, ...)

What am i doing wrong? (inArray, ...)

Hey guys!

I'm pretty new to jQuery, but i try to write a little tag plugin.
I have already got a piece of code, but somehow this doesn't work.

  1. $("#ranking tbody tr td").click(function(){
  2.       var tagToAdd = $(this).text();
  3.      var tags= [];
  4.      if (jQuery.inArray(tagToAdd, tags)) === -1){
  5.             alert("New tag is added!");
  6.             tags.push(tagToAdd);     
  7.       }else{
  8.             alert("Sorry this tag already exists!");
  9.       }
  10. })
So basically i want to add a tag to a filtering list. When i click on a table cell i get the text inside the cell. Look up if the same tag already exists and if not the tag is added and pushed to the array.
BUUT this doesn't work and I have no clue why (as i said it may be a dumb beginner mistake, so sorry if it sounds too easy).

Thanks in advance!
LG Internerd