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 1 of 1
  1. #1
    Regular Coder
    Join Date
    Apr 2005
    Location
    Ireland
    Posts
    122
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Setting the class dynamaically on menu list

    Hi

    Im new to JQuery and slowly picking it up.
    Im creating a large site and will require a number of differnt javascript functoins for various pages, therefore im trying to use namespaces.

    See my attached code.

    My first problem:
    I cannot get the <a> href to clear, any ides where my code is wrong?

    My Second problem:
    Any tips on how I have designed and implement my javascript and used JQuery would be greatly appreciated. I want to set up a good consistent layout and approach from the start.

    Thanks

    HTML:
    Code:
    {* Smarty *}
    
    <div id="topmenu">
     	<ul id="topMenuList">
    	   	<li><a href="javascript:void(0);" id="homePage">Home</a></li>
    	   	<li><a href="javascript:void(0);" id="membersPage">Members</a></li>
    	        <li><a href="javascript:void(0);" id="sportsPage">Sports</a></li>
    	   	<li><a href="javascript:void(0);" id="gamesPage">Games</a></li>
    	   	<li><a href="javascript:void(0);" id="rulesPage">Rules</a></li>
    	    <li><a href="javascript:void(0);" id="teamsPage">Teams</a></li>
    	</ul>
    </div>
    base.js will be included in every page.

    base.js
    Code:
    ADMIN = {};
    Js file for current menu page.

    menu.js
    Code:
    // onload
    $(document).ready(function() {
    	
    	var menu = new ADMIN.menu();
    	
    });
    
    ADMIN.menu = function() {
    	
    	// Get top menu list items and attach event handlers
    	$("#topMenuList").children().each( function(i) {
    		$(this).click( function () { ADMIN.menu.changeCurrentPage(this) } );
    	});
    }
    
    ADMIN.menu.changeCurrentPage = function(e) {
    	
    	var menuLink = $('a',e);
    	alert($(menuLink).id);
    	
    	$(e).addClass("current");
    	$(menuLink).href = '';
    }
    Last edited by tom123; 09-08-2009 at 10:26 PM.


 

Posting Permissions

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