Extract values from href attribute string using JQuery - Javascript jQuery

Javascript examples for jQuery:String

Description

Extract values from href attribute string using JQuery

Demo Code

ResultView the demo in separate window

<html>
 <head> 
  <meta name="viewport" content="width=device-width, initial-scale=1"> 
  <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> 
  <script type="text/javascript">
    $(window).load(function(){/*from   w ww.  ja v a 2  s  . co  m*/
var href = "?dir=ASC&sort=Vame".replace('?', "").split('&');
var myArr = {};
$.each(href, function(i, v){
   var s = v.split('=');
   myArr[s[0]] = s[1];
});
  console.log(myArr);
    });

      </script> 
 </head> 
 <body>  
 </body>
</html>

Related Tutorials