Results 1 to 3 of 3

Thread: Javascript to change a link's css class

  1. #1
    Administrator Chris's Avatar
    Join Date
    Feb 2003
    Location
    East Lansing, MI USA
    Posts
    7,048

    Javascript to change a link's css class

    Is there a way with javascript to indicate the current menu location with css?

    If self.url = link.href then link.href.cssclass = current?

    Something automatic rather than manually coding something in.
    Chris Beasley - My Guide to Building a Successful Website[size=1]
    Content Sites: ABCDFGHIJKLMNOP|Forums: ABCD EF|Ecommerce: Swords Knives

  2. #2
    Registered
    Join Date
    Apr 2006
    Posts
    184
    Something like this should work.... just call it when the page loads.

    Code:
    function checkLinks() {
    	var anchors = document.getElementsByTagName('a');
    	
    	for (var i=0; i<anchors.length; i++){
    		var anchor = anchors[i];
    			
    		if (anchor.href == location.href){
    			anchor.className = "someClass";
    		}
    	}
    }

  3. #3
    Administrator Chris's Avatar
    Join Date
    Feb 2003
    Location
    East Lansing, MI USA
    Posts
    7,048
    Thanks.... if it works its for the redesign of this site.
    Chris Beasley - My Guide to Building a Successful Website[size=1]
    Content Sites: ABCDFGHIJKLMNOP|Forums: ABCD EF|Ecommerce: Swords Knives

Similar Threads

  1. Script to turn all links into javascript or redirects
    By Westech in forum Website Programming & Databases
    Replies: 5
    Last Post: 10-20-2014, 04:34 PM
  2. How Do You Use Javascript Links?
    By incka in forum Search Engine Optimization
    Replies: 27
    Last Post: 12-27-2003, 03:28 PM
  3. Javascript Links
    By Mike in forum HTML, CSS, Layout, and Design
    Replies: 19
    Last Post: 12-25-2003, 09:34 AM
  4. Do javascript links still "refer" ?
    By Percept in forum Search Engine Optimization
    Replies: 2
    Last Post: 11-12-2003, 06:03 PM
  5. Affiliate Links Using Javascript
    By Mike in forum Advertising & Affiliate Programs
    Replies: 4
    Last Post: 08-18-2003, 09:17 AM

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
  •