I was also tormented the other day with a similar question, I did not find an exact solution, but they suggested something useful, in principle, in my case, it could be useful to you, too. I have 2 filters on my page, I also wanted to add a URL depending on the activated filter. I’ll drop the code to you.
function queryStringBuilder(id) { var paramsId = id; this.getQueryString = function() { var queryString = []; for (var i = 0; i < paramsId.length; i++) { var elem = $(paramsId[i]); if (elem.val().trim()) queryString.push((elem.attr('id') || elem.attr('name')) + "=" + escape(elem.val())); } return queryString.join("&"); } } var queryBuilder = new queryStringBuilder(['#dep-id', '#month']); function showQueryString(value) { location.search = value; } $('#dep-id').change(function() { showQueryString(queryBuilder.getQueryString()); }); $('#month').change(function() { showQueryString(queryBuilder.getQueryString()); });