Reputation: 107
I know in HTML you can link to an element by ID with #
in the address bar, but is it possible to do the same with the classname of the element?
Upvotes: 1
Views: 458
Reputation: 2110
It's possible if you don't mind using jQuery to get around this. The following code targets the class name and scrolls to it.
$("a").on("click",function() {
$('html, body').animate({
// add your class below
scrollTop: $('.contact').offset().top
// Scroll Speed
}, 2000);
});
Upvotes: 2
Reputation: 536
It's not possible to use class names as anchor tags in the address bar. Theoretically classes are supposed to be re-used , and one element can have several classes, so it's not a unique identifier
Upvotes: 1
Reputation: 723729
No. Fragment identifiers can only point to either an a
element with a name
of that identifier, or an arbitrary element with an id
of that identifier, assuming a conforming document where said element is unique.
A class name can apply to more than one element in a document, so it's not certain how a fragment identifier pointing to a class name should behave if there is more than one such element.
Upvotes: 0