SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2013
    Posts
    93
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Menu page selected and add class using jquery.

    Hi,

    I am looking for jquery plugin or jquery script to show selected active page.

    I will apply class to active element.

    Following is my header menu link

    Code:
    <tr valign="bottom"  class="topmenu">
    	<td width="317" align="left"><img src="includes/images/logo.jpg"></td>
    	<td width="10%"><a href="#" class="topmenu_active">Home</a></td>
    	<td width="12%"><a href="#">Tab1</a></td>
    	<td width="15%"><a href="#">Tab2</a></td>
    	<td width="8%"><a href="#">Tab3</a></td>
    	<td width="12%"><a href="#">Tab4</a></td>
    	<td width="10%">&nbsp;</td>
    </tr>
    I need solution using only jquery not css or any other way.

    Any idea?

    -Thanks

  2. #2
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,313
    Mentioned
    178 Post(s)
    Tagged
    9 Thread(s)
    Hi,

    So, you want to apply an additional class to whichever element has a class of "topmenu_active"?

    E.g.

    Code:
    <tr valign="bottom"  class="topmenu">
    	<td width="317" align="left"><img src="includes/images/logo.jpg"></td>
    	<td width="10%"><a href="#" class="topmenu_active MYCLASSHERE">Home</a></td>
    	<td width="12%"><a href="#">Tab1</a></td>
    	<td width="15%"><a href="#">Tab2</a></td>
    	<td width="8%"><a href="#">Tab3</a></td>
    	<td width="12%"><a href="#">Tab4</a></td>
    	<td width="10%">&nbsp;</td>
    </tr>

  3. #3
    SitePoint Enthusiast
    Join Date
    Apr 2013
    Posts
    93
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question

    Yes Pullo,

    When user will visit page for example Home then topmenu_active css class will be applied other wise no class.

    This will high light selected page.

    something like following url


    http://learnedstuffs.wordpress.com/2...-current-page/

  4. #4
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,313
    Mentioned
    178 Post(s)
    Tagged
    9 Thread(s)
    The code on the page you linked to compares the current url (in the address bar) with the value of the href attributes of the menu's anchor tags.

    So, what do your urls look like?

    Also, your href attributes currently have a value of "#" so this isn't going to work as you expect.

    Could you provide a link to the page where you are trying to make this work?

  5. #5
    SitePoint Enthusiast
    Join Date
    Apr 2013
    Posts
    93
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi ,

    Thanks Pullo

    I did this using session and it works.

    -Thanks


Tags for this Thread

Bookmarks

Posting Permissions

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