Reputation: 2917
I would like to add filtering to a "select category" page. E.g. "show only results with photos". The page consists out of multiple jQuery pages that allow a selection of the category within 3 levels. On the top I would like to add the form fields which should alter the href URL inside the pages upon select.
Is it possible to alter the URL of every single a href tag and not just one of them?
Upvotes: 0
Views: 492
Reputation: 30727
So something like this?
And this is just pseudo code - haven't tested it
Essentially, we use the a
selector to get all the anchors.
We then call on jquery's each
function.
And within the function we read the links ($(this)
) href and set it to the same + a query string.
This is just a very short example. You might need to do various checks.
$('a').each(function(){
$(this).attr('href', $(this).attr('href') + '?my=qstring');
});
Little update
OP wanted to know how to put this in a function to call at anytime.
Something like:
function updateUrls(){
// you might want to target urls in a given div, so something like
$('#myULOfUrls a').each(function(){
$(this).attr('href', $(this).attr('href') + '?my=qstring');
});
}
Then in your form-change, you simple call updateUrls()
Upvotes: 1