When you have a url like this www.example.com/#signup
, what the browser does is just to focus it's view on the HTML element with id signup
, is that right?
Is it possible to change the element's CSS style if it's focused in that way?
E.g. let's say I have a div element, with the id signup
, then if I enter www.example.com
, the div's background is white and if I enter www.example.com/#signup
it's yellow. Like "emphasizing" the sign up form. Is this at all possible?
The
:target
psuedo-class does exactly this.You can read the
window.location.hash
property when the page loads and apply the corresponding css classs. Something like: