jquery - Add param to url with value from href element -


i need add parameter sites url clicking on link value of element.

example:

<li><a href="dell">dell</a></li> <li><a href="dell">hp</a></li> 

when link clicked need add ?fss=dell url. second click should add value in element: ?fss=dell+hp , on each click. need reset click removes - keeps parameter before ?fss=

there scenario have parameter in place already, looks this: ?param=list, need click render this: ?param=list&fss=hp word "list" can few different things.

where start - need done trough vanilla js or jquery.

edit: posted solution worked - need add solution click removes fss , after it.

$(document).ready(function(){ $('a').on('click',function(e){ e.preventdefault(); if(location.href.indexof('?')===-1) location.href = location.href+"?   fss="+$(this).attr('href'); else location.href = location.href+"+"+$(this).attr('href'); }); }); 

are looking this?

$(document).ready(function(){  	$('a').on('click',function(e){  		e.preventdefault();  		if($(this).attr('href')!="reset"){  			if(location.href.indexof('?')===-1) location.href = location.href+"?fss="+$(this).attr('href');  			else location.href = location.href+"+"+$(this).attr('href');  		}  		else location.href = location.origin+location.pathname;  	});  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <a href="dell">dell</a>  <a href="hp">hp</a>  <a href="reset">reset</a>


Comments