Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.