[Solved] How to get attribute of href on the basis of selected text? [closed]


Try this :

put id for anchor tag

<a id="anchor1" href="https://stackoverflow.com/questions/25931155/site.com/register.php?mid=username&mode=bn&bid=1">

use below javascript

<script>
 var href = document.getElementById('anchor1').href;
 //get index of ?
 var indexStart = href.indexOf('?');
 var indexLast = href.length;
 //get href from ? upto total length
 var params = href.substring(indexStart+1, indexLast);
 //get tokens with seperator as '&' and iterate it
 var paramsArray = params.split("&");
 for(var i=0;i<paramsArray.length;i++)
 {
   //get key and value pair
   var paramKeyValue = paramsArray[i];
   var keyValue = paramKeyValue.split('=');
   alert("Key="+keyValue[0]+" and value="+keyValue[1]);
 }
</script>

Demo Link

8

solved How to get attribute of href on the basis of selected text? [closed]