title: Use value from data attribute as url parameter
body: <p>As base I use: <a href="http://stackoverflow.com/a/10997390/11236">http://stackoverflow.com/a/10997390/11236</a></p>
  
  <p>On click, I want to take the data attribute value of the clicked element and use it as url parameter. I don't want to destroy the actual behavior, I just want to extend it. I am trying a few hours now, but without a result.</p>
  
  <p>HTML</p>
  
  <pre><code>&lt;div class="button one"&gt;Click me&lt;/div&gt;
  &lt;div class="button two" data-url="this-should-be-the-parameter"&gt;Click me&lt;/div&gt;
  </code></pre>
  
  <p>JS URL Controler</p>
  
  <pre><code>  function updateURLParameter(url, param, paramVal){
        var newAdditionalURL = "";
        var tempArray = url.split("?");
        var baseURL = tempArray[0];
        var additionalURL = tempArray[1];
        var temp = "";
        if (additionalURL) {
            tempArray = additionalURL.split("&amp;");
            for (var i=0; i&lt;tempArray.length; i++){
                if(tempArray[i].split('=')[0] != param){
                    newAdditionalURL += temp + tempArray[i];
                    temp = "&amp;";
                }
            }
        }
  
        var rows_txt = temp + "" + param + "=" + paramVal;
        return baseURL + "?" + newAdditionalURL + rows_txt;
    }
  
      var newURL = updateURLParameter(window.location.href, 'locId', 'newLoc');
      newURL = updateURLParameter(newURL, 'resId', 'newResId');
  </code></pre>
  
  <p>JS Click Handler</p>
  
  <pre><code>$( ".button" ).click(function() {
    window.history.replaceState('', '', updateURLParameter(window.location.href, "specificurl", "customvalue"));
  });
  </code></pre>
  
  <p>So, I have to check, if the clicked div contains the attribute "data-url", and if yes, this should be used as parameter for "customvalue"</p>
  
  <p>As result, Url should look like:</p>
  
  <pre><code>Click on ".buton.one": xyz.com/?specificurl=customvalue
  Click on ".buton.two": xyz.com/?specificurl=this-should-be-the-parameter
  </code></pre>