html - How to set parameter and its value to HREF dynamic using javascript -
i have link following
<a id="dynamiclink" href="http://www.w3schools.com?username=test">visit w3schools</a>   i change value of username test test1.
how using javascript?
could me on this?
i suggest using library work uris. provide consistency. here example using uri.js:
// our <a> element  var l = document.getelementbyid('dynamiclink');    // use uri.js work uri  // http://medialize.github.io/uri.js/  var uri = uri(l.href);    // query string object  var qs = uri.query(true);    // change our value  qs.username = 'test1'    // update uri object  uri.query(qs);    // set our new href on <a> element  l.href = uri;  <script src="https://cdnjs.cloudflare.com/ajax/libs/uri.js/1.15.2/uri.min.js"></script>    <a id="dynamiclink" href="http://www.w3schools.com?username=test&someotherkey=val">visit w3schools</a>  
Comments
Post a Comment