Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to jump to HTML element by class instead of id?

I know that you can jump to elements by id but is it possible to jump to elements by class?

Am I going to have to use javascript to add an id to the element with that class name?

It would be a pain to add ids manually every time, the class names will already be there.

*I could have worded my question a bit better. I meant to use class names that are already there as anchor tags to jump to. The html I'm working with has class names for a LOT of individual elements and no ids. I'm wanting to jump to those elements without having to add an id to each and every one.

like image 603
Unwieldy Lunchbox Avatar asked Mar 22 '23 23:03

Unwieldy Lunchbox


1 Answers

window.scrollTo(0, document.querySelector(".className").offsetTop);

http://jsfiddle.net/DerekL/kEFp7/

like image 69
Derek 朕會功夫 Avatar answered Apr 05 '23 19:04

Derek 朕會功夫