Jump to content

Better way of coding this ?


BarryChuckle

Recommended Posts

Hey guys be easy on me it's my first post :P

 

Okay I've attached some code which I done earlier. I'll explain it first - I have a header which is included throughout each of the pages on my website. When a page is selected the header is then given the class selected to change the style to show the current page is selected.

 

I have a terrible feeling that there is a bette way of coding this.. I am not sure though because I am not that experienced.

 

It works but it's terribly messy (It runs when the page has loaded .read();)

 

	 switch(document.title){
		case('link1'):
			$('#1').addClass('selected');
			break;
		case('link2'):
			$('#2').addClass('selected');
			break;
		case('link3):
			$('#customers').addClass('selected');
			break;
		default:
			$('#1').addClass('selected');
	 }

 

So is there a better way of getting this to work ? Also is there any cool articles that can help me improve my coding (I can generally get things to do what I want but with very shoddy code imo. Thanks again guys!

Link to comment
https://forums.phpfreaks.com/topic/249292-better-way-of-coding-this/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.