PDA

View Full Version : Is there a way to put a link in active state indication with just jquery?



madnhate
10-08-2011, 02:46 AM
Is there a way to make a page link be activated as in being indicated you are on that page with just javascript or would that be more css?


For example if I was in HOME it would be indicated with let's say an underline but if I click info when that page loads INFO will be underlined? Can it be done with javascript or just css?

djr33
10-08-2011, 05:15 PM
Can you give us a link to your page and explain with which links and under which circumstances you want this to happen?

CSS has specific pseudo-classes for links-- for <a> tags. They include :hover :active: and :visited. :hover is applied when the mouse is over the link; :active is applied when you click on a link and it is loading; :visited is applied when the URL is in your history (when you have already been to that page).

That's as much as CSS can do. Is that what you want?


Javascript or Jquery could change how a link looks. But you'd need to determine the circumstances for doing this.


I think what you're looking for is how you can indicate that you are already on a certain section. And then the link to that section will look different than links to other sections.


This is more often done using a serverside language like PHP. It is possible to do a similar thing using Javascript: you would check the current page's URL and look for any URL that matches the section. Then change the style of that URL as needed. But that is complicated.

I think it's easier to use PHP to generate all of the links and check at that point to see if one should be formatted in a special way.


If you want more specific help, post more information.

For now, see if any of these search results can help:
http://www.google.com/search?q=navigation+menu+active+page

Both Javascript and PHP options (at least) are included.

madnhate
10-17-2011, 08:59 PM
Yeah I'm sorry what I meant is indication you are already on a certain section.
My wording is confusing I apologize for that. I remember learning a while ago however that it can be done with css. I think it was using classes and/or IDs css styling. But PHP and javascript would probably be good as well. I'll look into your link and thanks.

On a side note where would you recommend me going to learning how to use PHP and mySql/databases?

djr33
10-18-2011, 12:28 AM
You can't use CSS alone because CSS won't know where you are. But you can use CSS to set an "active" style and apply the "active" class to any link/tab you'd like.

So you would use Javascript to check the current location and see which link/tab it corresponds to.

Personally I'd use PHP because I build my sites in PHP anyway and it would be easy enough that way. You could do it in JS, but it will be more reliable (and I think a little easier) in PHP.


I like the tutorial at this site:
http://php-mysql-tutorial.com

But I'd recommend learning in general by hands on experience-- start with a small project and build up.