Matthew Matthew - 4 years ago 144
Javascript Question

jQuery: Forward to url #link2 when people click on #link1

Let's say someone clicks on:

<a href="#" class="filter">Stillness Furniture</a>

The link in the browser will just go to

Here is the code housing that link:

<nav id="portfolio-filter">
<li class="filter"><a href="#" class="filter">View All</a></li>
<li class="filter"><a href="#" class="filter">Stillness Furniture</a></li>

I want the link to go to #portfolio-filter instead of just #, now obviously I could change the link href, but this is a WordPress theme and editing it would mean I have to change it every time I update the theme.

How would I be able to make the browser jump down to id#portfolio-filter when someone clicks that link?

Something like this is all I have so far?

$(document).on("click", "a.filter", function(){
//do something

(taken from Onclick function based on element id)

Thanks in advance for any help.

Answer Source

So it seems like you want them to all go to the same place, if I understand you correctly. So you could rewrite the links if you wanted to...

$('#portfolio-filter').find('a.filter').attr('href', '#portfolio-filter');
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download