Add class to table row based on index

  • AnarchY SI
  • Web Master
  • Web Master
  • User avatar
  • Posts: 2521
  • Loc: /usr/src/MI

Post 3+ Months Ago

So, I've acquired a project written in C# ASP.NET. This project uses a left side menu for the navigation. The menu is a simple table (that has an ID) with each link on it's own row in the table. What I would like to do is highlight the table row for whichever "page" the user is currently on. The difficulty is the entire site is all in the same file, so I can't explicitly set the background color or assign an ID to the row. Is there something in Javascript that can accomplish this? I've tried a few different methods of doing this, such as retrieving the row object as is done here http://www.daniweb.com/forums/thread284166.html (the more general case) and adding a class to that by both setting .className and using jQuery's addClass method, but nothing happened.

Any help would be greatly appreciated.
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9091
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

So there is no way in your C# code that you could write a way to mark the current page's link? If I were in your shoes I would write a bit of code to insert a class on the current page's link and then use CSS make that class a different color.

If you really want to go the all JavaScript Route, one thing you could do is use some JavaScript to first detect the current URL:

JAVASCRIPT Code: [ Select ]
document.URL


Then with that figured out, you could use jQuery to match which elements in your navigation have the same link and use the jQuery's addClass method to make that link stand out differently. Remember once you add whatever class to an element you want, make sure your CSS is working properly for that class to actually make the link stand out differently.

Post Information

  • Total Posts in this topic: 2 posts
  • Users browsing this forum: No registered users and 68 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.