Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 2 of 2 FirstFirst 12
Results 16 to 26 of 26
  1. #16
    Regular Coder Lerura's Avatar
    Join Date
    Aug 2005
    Location
    Denmark
    Posts
    901
    Thanks
    0
    Thanked 118 Times in 117 Posts
    Sorry I made a copule of typos: I forgot () after the second function and the $ in front of it all.
    Fixed code:
    Code:
    $(function(){
    $('#treemenu1').find('a').each(function(){
    if (this.href==("index.php"+location.search)){
    this.addClass('Active');
    }
    });
    Just paste as is.

  2. #17
    New Coder
    Join Date
    Jun 2012
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Still no luck... :-/ Check it out...

    I have it as this:

    Code:
    <script type="text/javascript">
    $(function(){
    $('#treemenu1').find('a').each(function(){
    if (this.href==("index.php"+location.search)){
    this.addClass('Active');
    }
    });
    </script>

  3. #18
    Regular Coder Lerura's Avatar
    Join Date
    Aug 2005
    Location
    Denmark
    Posts
    901
    Thanks
    0
    Thanked 118 Times in 117 Posts
    I think I am getting too tired.
    The problem wasn't the extra set of }), which turns out not being extra at all,
    but that I forgot what I mensioned above.
    so
    Code:
    <script type="text/javascript">
    $(function(){
    $('#treemenu1').find('a').each(function(){
    if (this.href==("index.php"+location.search)){
    this.addClass('Active');
    }
    })
    });
    </script>

  4. #19
    New Coder
    Join Date
    Jun 2012
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts
    OK, that code looks correct but trying out the functionality for yourself... it's still not keeping the current variable choice BOLD... I am officially stumped... what else could it be? Do you need any other pieces of code for me to paste?

  5. #20
    Regular Coder Lerura's Avatar
    Join Date
    Aug 2005
    Location
    Denmark
    Posts
    901
    Thanks
    0
    Thanked 118 Times in 117 Posts
    It is somehow not seen as a reload, so this should work.
    Code:
    <script type="text/javascript">
    $('#treemenu1').find('a').click(function(){
    $('#treemenu1').find('a').each(function(){
    if (this.href==("index.php"+location.search)){
    this.addClass('Active');
    }else{
    this.removeClass('Active');
    }
    })
    });
    </script>

  6. #21
    New Coder
    Join Date
    Jun 2012
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Not working still... I did exactly as you said and put in the JS code:

    Code:
    <script type="text/javascript">
    $('#treemenu1').find('a').click(function(){
    $('#treemenu1').find('a').each(function(){
    if (this.href==("index.php"+location.search)){
    this.addClass('Active');
    }else{
    this.removeClass('Active');
    }
    })
    });
    </script>
    *sigh*

  7. #22
    Regular Coder Lerura's Avatar
    Join Date
    Aug 2005
    Location
    Denmark
    Posts
    901
    Thanks
    0
    Thanked 118 Times in 117 Posts
    I finally found the right solution: (a cup of coffee made the difference )
    Code:
    <script type="text/javascript">
    $(function(){
    $('#treemenu1').find('a').each(function(){
    if (this.href==location.href){
    $(this).addClass('Active');
    }else{
    $(this).removeClass('Active');
    }
    });
    });
    </script>
    Last edited by Lerura; 06-19-2012 at 04:07 AM.

  8. #23
    New Coder
    Join Date
    Jun 2012
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Lerura View Post
    I finally found the right solution: (a cup of coffee made the difference )
    Code:
    <script type="text/javascript">
    $(function(){
    $('#treemenu1').find('a').each(function(){
    if (this.href==location.href){
    $(this).addClass('Active');
    }else{
    $(this).removeClass('Active');
    }
    });
    });
    </script>
    IT WORKS! Can you explain to me what was wrong before and what it does now? That is how I learn Thanks!

  9. #24
    Regular Coder Lerura's Avatar
    Join Date
    Aug 2005
    Location
    Denmark
    Posts
    901
    Thanks
    0
    Thanked 118 Times in 117 Posts
    I will try!

    I forgot that since addClass and removeClass are jQuery functions, the reference to the object must be written $(this), instead of this

    The other issue that I discovered while playing with the code is that
    Code:
    this.href
    returns the absolute URL of the link, and not just the relative URL that I expected;

    And now I have just noticed that I forgot the remove
    Code:
    else{
    $(this).removeClass('Active');
    }
    when changing from when i changed from:
    Code:
    $('#treemenu1').find('a').click(function(){
    to
    Code:
    $(function(){
    it is necessary when the code is "onclick" as it needs to reset the previous assignment, but when "onload" the assignments are automatically reset, due to the reloading of the page.

    It does no harm, but is completely necessary "onload"
    ----
    Just ask away. if you need more information.

  10. #25
    New Coder
    Join Date
    Jun 2012
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ahhhhhhhh OK... Thanks so much man! I appreciate it

  11. #26
    New Coder
    Join Date
    Jun 2012
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Lerura (or anyone else),

    In my tree menu seen at http://www.wrcc.dri.edu/monitor/WWDT/index.php, is there a way to make the Variable sub menu and Region sub menu independent of eachother in terms of being bold when clicked... So for example, If I click PDSI I want that to become bold and then if I click Arizona I want that to become bold as well. I would like variable and region to both be bold when the user clicks on it. This makes it easier for the user to know what he/she clicked by just looking at the tree menu. Right now, only the active or recently clicked variable/region become bold.

    Does that make sense?

    Thanks!


 
Page 2 of 2 FirstFirst 12

Tags for this Thread

Posting Permissions

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