I have a fairly long list of names, and I would like to create a quick, easy navigation to scroll through the names starting with a specific character.
So, if I had links like -
<a href="a">A</a>
<a href="b">B</a>
<a href="c">C</a>
I usually had anchors or divs with identifiers set between characters and scrolling to them. In this case, I do not have anchors or divs before each new letter of the beginning, I just have a long list.
Let's say that every name in the list is in <h1 class="name">Someone Name</h1>
I can get a letter from
$('a').click(function(e) {
e.preventDefault();
var letter = $(this).attr('href');
});
So, as soon as I have this letter, is there a way to find the first element that is h1.namewhich starts with this letter using jQuery?
source
share