Href not longer working because of .click function

Hi have a page in my websit called artwork. On this page I have a submenu with the different categories. The photos from this categories will appear on the same page (artwork) coming from the database. For the sake of showing the active category I used the following function:


$('#submenu a').click(function(e) {
  e.preventDefault();
    $('#submenu a').removeClass('activesub');
    $(this).addClass('activesub');
});

The function is doig what you would expect it to do. The problem is, the href isn’t working any longer. What should I change in this function too:

  1. make sure you see the active category
  2. the href attribute is still working

Thank you in advance.

Is it the same link that is being clicked on, to see the active category and that you click on to go somewhere else?

If not, we’ll need more information about things. Perhaps a test page that demonstrates the problem - that’s the best way for us to get all of the information that we need about the situation.

Hi Paul. Thank you for the responce. Everything is happening on just one page, but there are several submenu items. All redirecting to the same page where they are located, only all with a different url variable. On this page you’ll see what should happens after you click one of the categories (e.a. Porsche, Hemingway etc) and on [URL=“http://diem.sothenwhat.com/peter_diem_artwork2.cfm”]this page what happens after I included the function to get the active link on the submenu items.

Thanks - so when someone clicks on Hemmingway, they are taken to “http://diem.sothenwhat.com/peter_diem_artwork.cfm?artwork=hemingway” which results in a whole new page being loaded. Your attempt to adjust the class of the active link is not going to succeed, because the current page is replaced by a whole new page.

There are a couple of different ways to deal with this. One is to make the artwork changes without reloading the page, and the other is to allow the page to reload and look at the URL of the page when it loads up, to determine which link to make active.

The former option can be a cleaner option, but it does require serious changes to how your page works.

If you choose the latter option, you won’t need your click event and can search for the querystring as the page loads up, and set activesub with something like this:


$(function () {
    $('#submenu a[href*="' + location.search + '"]').addClass('activesub');
});

Hi Paul. First of all, thank you for the responce!

Yes you’re right, I should have go for some form of Ajax in this, but I am way to lat to do that right now. So I will indeed go for the second option you gave me. Thank you so much…