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.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Dec 2008
    Posts
    117
    Thanks
    14
    Thanked 0 Times in 0 Posts

    jquery: to set the <a> link to return true again

    Hi,
    I have menu which nested with sub menu like this,

    Code:
    <div id="menu">
     <ul>
     <li><a href="#">menu1</a>
       <ul>
          <li>sub1</li>
          <li>sub2</li>
       </ul>
    </li>
    <li><a href="#">menu2</a></li>
    <li><a href="#">menu3</a></li>
    <li><a href="#">menu4</a></li>
    </ul>
    </div>


    and I just want the last item in the menu to return true when it is clicked. So my idea is to set all item to return false, then set the last item to return true again.

    Code:
    $('#menu > ul > li > a').click(function(){
    				return false;
    			});
    			
    $('#menu > ul > li > a:last').bind('click', function() {
    			  return true;
    			});
    but I think probably it is wrong bcos it wont work! many thanks if u have any ideas to do this.

    cheers,
    Lau

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Where do you want the "true" or "false" to return to? All jQuery functions return jQuery objects.

  • #3
    Regular Coder
    Join Date
    Dec 2008
    Posts
    117
    Thanks
    14
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fumigator View Post
    Where do you want the "true" or "false" to return to? All jQuery functions return jQuery objects.
    a link in the last item, such as,

    <li><a href="index.php">menu 4</a></li>

    is it possible?

  • #4
    Regular Coder
    Join Date
    Dec 2008
    Posts
    117
    Thanks
    14
    Thanked 0 Times in 0 Posts
    i think i just worked it out in this way...

    Code:
    $('#menu > ul > li > a:last').bind('click', function() {
    			  var path = $(this).attr('href');
    			  document.location = path;
    			  return true;
    			});
    it works fine...


  •  

    Posting Permissions

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