Reputation: 21
Let me try to make myself clear: I have a menu that, when you click on a link, it jumps down to the content in that same page. In other words, it's just an link that anchors to the content. Could I possibly change the color of, let's say, the content's h1 tag after clicking on the link?
I also thought of a different way of solving, but I'm not quite sure: could I change the color of a H1 tag depending on its position as you scroll down a page?
Cheers!
Upvotes: 0
Views: 1634
Reputation: 13800
The CSS3 :target pseudo-selector will do what you want, but if browser support is an issue, you could do something like this:
jQuery
$('nav li a').click(function (e) {
var targ = $(this).attr('href');
$('html, body').scrollTop($("'" + targ + "'").offset());
$("'" + targ + "'").css('color','red');
e.preventDefault();
});
HTML:
<nav>
<ul>
<li><a href="#someElement">Click here!</a></li>
</ul>
</nav>
Upvotes: 0
Reputation: 27640
Yes, you can use the :target pseudo-selector in CSS.
See here for the current browser compatibility: http://www.quirksmode.org/css/contents.html
Upvotes: 0