I have a script that adds a parameter to the url on a click - and replaces the the parameter with another on the second click. This works great.
However there is a scenario when there already is a parameter in place - and I then need this click to replace that value.
Example:
Click one gives
?param=largegrid
Second one replaces the value and gives
?param=smallgrid
But sometimes the url looks like this:
?param=grid or param=grid&fss=tablet
in this case i want the click to replace the first value so the url looks like
?param=large or param=largegrid&fss=tablet
and the same for the second click.
$('.click10').on('click', function() {
console.log("Clicked");
var url = window.location.pathname;
var url = window.location.href;
if (url.indexOf('?param=largegrid') > -1) {
url = url.replace("?param=largegrid", "") + '?param=smallgrid'
} else {
url = url.replace("?param=smallgrid", "") + '?param=largegrid'
}
window.location.href = url;
});