SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Dec 2010
    0 Post(s)
    0 Thread(s)

    jQuery - Active Navigation with Class

    Hello everyone.

    I am attempting to set it so that upon clicking a link within this Joomla site (from the navigation menu), the link will become bold. I have already implemented CSS for ".active" and set the "LI" class to 'active' to the first class.

    I have done a search for the JQuery code to do this, but each example that I tried did not work at all. The class remained to be on the first link, home.

    Please see my existing code below and advise if you may please.

    URL of test page --

    CSS for '.active' and 'nav' --
    .nav {
    	background: url('../images/navbg.jpg') repeat-x;
    	border: 1px #a7a9ac;
    	padding-bottom: 3px;
    	padding-left: 10px;
    	margin-bottom: 30px;
    	height: 125px;	
    .nav ul {
    	margin: 0; 
    	padding: 0; 
    	list-style: none;
    .active {
    The HTML for the menu --
    <div class="nav" id="menu">
    <ul id="nav">
    <li class = "active"><a href="index.php">Home</a></li>
    <li><a href="index.php?option=com_content&amp;view=article&amp;id=47">Online Store</a></li>
    <li><a href="?url=keynote_topics">Keynote Topics</a></li>
    <li><a href="?url=contact">Contact Us</a></li>
    <li><a href="">Blog</a></li>
    Existing example of JQuery Code --
    $('.nav li a').click(function()
      $('.nav li').removeClass('active');

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Christchurch, New Zealand
    104 Post(s)
    4 Thread(s)
    When the link is clicked, the jQuery may well be adding the class, but after that the page is thrown away so that the clicked link can then load a new page.

    You need the loading page to know which one to make active.

    Here's an intro to the idea: Including Navigation Code On All Pages (Even With Current Navigation Highlighting!)

    and here's a video tutorial on putting it in to practice: Current Nav Highlighting: Using PHP to Set the Body ID
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Posting Permissions

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