JQuery onClick GoTo ID or class

For some odd reason, my header all got messy when I hit tag A to go to the id. So, instead, is there a way to use jQuery for this, such as Click (), Goto ID?

<a href="#allreviewstop">Read Reviews (1)</a>
<div style="height:1500px;"> Really Long Stuff</div>
<div id="allreviewstop"> My Reviews go down here</div>

This is the page I'm dealing with. Click here.

+3
source share
4 answers
$("div").click(function() {
    window.location.hash = "#"+$(this).attr("id");
}

This is what you need?

[edit] I can’t remember whether you need # or not. Try if this does not work.

+2
source

Try the jquery ScrollTo plugin -

also check demo

$(function(){
    $("#goTop").click(function(){
      $.scrollTo($("#nav"), { duration: 0});
    });
});
+2
source
0

window.location.hash . , :

var navigationFn = {
    goToSection: function(id) {
        $('html, body').animate({
            scrollTop: $(id).offset().top
        }, 0);
    }
}

( someID - , ):

navigationFn.goToSection('#someID');

With this, you can also change the speed of the animation (I have it at 0), so that it is instantaneous, but you can pass the value of the function so that the code is reused.

0
source

All Articles