hkk
hkk

Reputation: 23

jquery to scroll to section of page, without class or id in HTML

So the html file for this challenge doesn't have any mark-ups, but the mission is to have the screen scroll down to each section when you click on each li. Anybody know how to scroll to different section using jquery, without any plug ins?

Upvotes: 1

Views: 365

Answers (2)

you-rick
you-rick

Reputation: 185

try this

$('.list li').on('click', function() {
   var tabIndex = $(this).index();
   $('body').scrollTop( $('section').eq(tabIndex).offset().top );  
});

DEMO - http://jsfiddle.net/R5PXH/481/

Upvotes: 1

Jon Ander
Jon Ander

Reputation: 780

try this:

function goToAnchor(anchorID) {
    $(document).scrollTop( $(anchorID).offset().top );  
});

and to use it:

goToAnchor('#section-id');

Upvotes: 0

Related Questions