SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Wizard donboe's Avatar
    Join Date
    Jun 2010
    Location
    Netherlands
    Posts
    2,107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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:
    Code:
    $('#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.
    “Good artists copy, great artists steal” (Pablo Picasso - 1934)

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,712
    Mentioned
    102 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by donboe View Post
    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
    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.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Wizard donboe's Avatar
    Join Date
    Jun 2010
    Location
    Netherlands
    Posts
    2,107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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 this page what happens after I included the function to get the active link on the submenu items.
    “Good artists copy, great artists steal” (Pablo Picasso - 1934)

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,712
    Mentioned
    102 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by donboe View Post
    On this page you'll see what should happens after you click one of the categories (e.a. Porsche, Hemingway etc) and on 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:

    Code javascript:
    $(function () {
        $('#submenu a[href*="' + location.search + '"]').addClass('activesub');
    });
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  5. #5
    SitePoint Wizard donboe's Avatar
    Join Date
    Jun 2010
    Location
    Netherlands
    Posts
    2,107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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......
    “Good artists copy, great artists steal” (Pablo Picasso - 1934)


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •