title: function to retrieve url variables using javascript and Jquery?
body: <p>in my script there a simple list shows links for editing</p>
  
  <pre><code>&lt;ul&gt;
  &lt;li&gt;&lt;a href="edit.php?id=5" class="edit"&gt;click here&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href="edit.php?id=5" class="edit"&gt;click here&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href="edit.php?id=5" class="edit"&gt;click here&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href="edit.php?id=5" class="edit"&gt;click here&lt;/a&gt;&lt;/li&gt;
  &lt;/ul&gt;
  </code></pre>
  
  <p>what i need is to read the variable id so i can send it through .ajax call and i tried this function</p>
  
  <pre><code>$(document).ready(function(){
      function getUrlVars() {
          var vars = [], hash;
          var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1)
                                           .split('&amp;');
          for(var i = 0; i &lt; hashes.length; i++)
          {
              hash = hashes[i].split('=');
              vars.push(hash[0]);
              vars[hash[0]] = hash[1];
          }
          return vars;
       }
       $('.edit').click(function(){
           var test = getUrlVars()["id"];
           alert(test);
       });
  });
  </code></pre>
  
  <p>When I clicked on the link, the alert message shows <code>undefined</code>. </p>
  
  <p>I tried another function:</p>
  
  <pre><code>$(document).ready(function(){
      var urlParams = {};
      (function () {
          var match,
                 pl = /\+/g,  // Regex for replacing addition symbol with a space
             search = /([^&amp;=]+)=?([^&amp;]*)/g,
             decode = function(s) { 
                 return decodeURIComponent(s.replace(pl, " ")); 
             },
             query  = window.location.search.substring(1);
             while (match = search.exec(query))
                 urlParams[decode(match[1])] = decode(match[2]);
       })();
       $('.edit').click(function(){
           var test = urlParams["id"];
           alert(test);
       });
   });
  </code></pre>
  
  <p>... but even this also shows up the alert message <code>undefined</code>.</p>