MShack MShack - 2 years ago 77
Javascript Question

Scroll to top on click of onclick cell

I have 2 tables set up, and on mobile I hide one and show the other

of a
or icon, I need to have offset position set to top when I click, but having issues getting this done

When I click on this HTML

<a title="" style="cursor:pointer" onclick="updateStarter('1137','')"></a>

I want the shown table to open up at top of

When I click on this HTML

<tr class="eventablerow" style="cursor:pointer" onclick="showLineupTab(1,true)"></tr>

I want the shown table to open up at top of

I have this working on one, but I wanted to be more specific to the
for both instances when I click as I have other data in the tables you can click on, and when you do it causes
top to trigger

var jump = $(this).attr('href');
var new_position = $('#left-head').offset();

Answer Source

Well I'm not sure of the real position of your table and div#right-head but I can suggest you to try this:

$(' a , tr').click(function(){
    var jump = $(this).attr("href");
    var _top = $("#left-head").offset().top;
    $("html, body").animate({"scrollTop":_top+"px"}, 1000);
    return true;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download