How to get the value from the GET parameters using jQuery?

Very often we face challenge need get values from URL (GET query parameters) and if in PHP is a special function ($_GET) then in JavaScript and in particular jQuery such function is absent. Below, I’ll provide example that function, that I found in the Network.

Get URL parameters using jQuery?

Problem: How to get the value from the GET parameters using jQuery?

Solution: 

// Get Url Parameter From URL
function getUrlParameter( name, url ) {
    if ( !name ) {
		return;
	} else {
		var url = (url) ? url : window.location.href;
		var results = new RegExp( '[\?&]' + name + '=([^&#]*)' ).exec( url );
		return results[1] || 0;
	}
}

Source:

  1. https://www.sitepoint.com/url-parameters-jquery/

Leave Comment

Your email address will not be published. Required fields are marked *