This is a very simple way of highlighting the current page of a menu. It uses javascipt to take the current url and cross checks it against any URLs that match in the menu. If one matches then add an â€˜activeâ€™ class to it. Be careful with #â€™s though. because a traling # in the URL would screw this up. Though you could always build in a function to strip out #â€™s before getting to the selectorâ€¦ Please note: if at first this doesnâ€™t work try using document ready or replacing $â€™s for jQuery..
- // Get current url
- // Select an a element that has the matching href and apply a class of 'active'. Also prepend a - to the content of the link
- var url = window.location;
- $('a[href="'+url+'"]').prepend('// ');
CommentsSubscribe to comments
You need to login to post a comment.