View Full Version : jQuery Setting the class dynamaically on menu list

09-08-2009, 10:19 PM

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.



{* 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>

base.js will be included in every page.


ADMIN = {};

Js file for current menu page.


// 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);

$(menuLink).href = '';