I know this is a little bit hard to understand, but I've seen some sites using the ID of an element in the url to send you somewhere, and I was wondering if it's also possible with classes.
I don't think this is private or something like that because anyone can get it by inspecting the page. I also tryed with a dot (".class"), but it unfortunately didn't work.
So is there another way of doing this with other than IDs?
I know this is a little bit hard to understand, but I've seen some sites using the ID of an element in the url to send you somewhere, and I was wondering if it's also possible with classes.
I don't think this is private or something like that because anyone can get it by inspecting the page. I also tryed with a dot (".class"), but it unfortunately didn't work.
So is there another way of doing this with other than IDs?
Share Improve this question edited Feb 11, 2021 at 18:52 asked Aug 30, 2016 at 20:24 user6312124user6312124 4-
<a href="#div">Content</a>
– Arnav Borborah Commented Aug 30, 2016 at 20:26 - clicking on a link with a hashtag will scroll you to the point on that page where that id occurs. it's called a bookmark. if you used classes how would the browser know which one to scroll to? why do you want to do that anyway? – Robert Parham Commented Aug 30, 2016 at 20:29
-
Hashes can only refer to
id
attributes andname
attributes, but notclass
or any other attribute. – mwcz Commented Aug 30, 2016 at 20:29 - 1 Wrong answer Arnav. But anyway, I don't think there's anything that can be done with classes as there is no guarantee a class is unique, therefore how does the browser know which to scroll to? Could implement some behavour with JavaScript which takes the first – Joseph Young Commented Aug 30, 2016 at 20:29
1 Answer
Reset to default 8You cannot do this with classes because they're not unique. The browser needs to know exactly where to send you, and using a class name instead of an ID would be ambiguous.