0

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.

e.g.: enter image description here

Is it possible to alter the URL of every single a href tag and not just one of them?

1 Answer 1

1

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()

Sign up to request clarification or add additional context in comments.

1 Comment

Yes, this might go into right direction. How could I bind it to a change event. I would like to have that function executed every time the user changes the forms in the filter section.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.