Search code examples
jqueryclassclickgoto

jQuery onClick GoTo ID or Class


For some odd reason my Header gets all messed up when I click on an A tag to go to an ID. So instead is there a way to use jQuery to do this, such as a 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


Solution

  • $("div").click(function() {
        window.location.hash = "#"+$(this).attr("id");
    }
    

    Is that what you're after?

    [edit] I can't remember if you need the # or not. Try it without if it doesn't work.