jQuery- How to get the GET variable from a URL -


in js file, outputting hyperlinks based on data pulled api:

output += '<a class="reg_link" href="'+regobj.href+'?reg='+value+'" title="'+regobj.title+'" target="_blank">'; 

this works fine. however, later want find out ?reg= value is.

$(".reg_link").each(function() {   // how get variable url? }); 

i'm trying grab whatever value of variable is. how do that?

from how can query string values in javascript?

you don't need jquery purpose. can use pure javascript:

function getparameterbyname(name) {     name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");     var regex = new regexp("[\\?&]" + name + "=([^&#]*)"),         results = regex.exec(location.search);     return results == null ? "" : decodeuricomponent(results[1].replace(/\+/g, " ")); } 

usage:

var reg = getparameterbyname('reg'); 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -