title: append url parameter if exists or add if not exists jQuery
body: <p>I am creating a filter based on size, color etc. So it is possible to select multiple items. When I click each item it should append to current URL. Please check the below URL,</p>
  
  <p><code>If parameter not exists in URL</code></p>
  
  <pre><code>http://example.com/category-3?tracker=Q2F0ZWdvcnkgMw&amp;color=White
  </code></pre>
  
  <p><code>If parameter exists and selected same color</code></p>
  
  <pre><code>http://example.com/category-3?tracker=Q2F0ZWdvcnkgMw&amp;color=White
  </code></pre>
  
  <p><code>If parameter exists and selected multiple colors</code></p>
  
  <pre><code>http://example.com/category-3?tracker=Q2F0ZWdvcnkgMw&amp;color=White-Black
  </code></pre>
  
  <p>How to implement the same using jQuery. I have tried using below code,</p>
  
  <pre><code>function setGetParameter(paramName, paramValue) {
      var url = window.location.href;
      var hash = location.hash;
      url = url.replace(hash, '');
      if (url.indexOf(paramName + "=") &gt;= 0) {
          var prefix = url.substring(0, url.indexOf(paramName + "="));
          var suffix = url.substring(url.indexOf(paramName + "="));
          suffix = suffix.substring(suffix.indexOf("=") + 1);
          suffix = (suffix.indexOf("&amp;") &gt;= 0) ? suffix.substring(suffix.indexOf("&amp;")) : "";
          url = prefix + paramName + "=" + paramValue + suffix + "-";
      } else {
          if (url.indexOf("?") &lt; 0)
              url += "?" + paramName + "=" + paramValue + "-";
          else
              url += "&amp;" + paramName + "=" + paramValue + "-";
      }
      window.location.href = url + hash;
  }
  </code></pre>
  
  <p>The above code works with single parameter value. For multiple values how to alter the above code.</p>