0

I have a <div> popup that is shown when a link is clicked. It has scrollable content if there is overflow.

I just need to have the <div> at the top of the scrollable area if the link is clicked again. This is working perfectly in Chrome and Firefox, however in IE, it remains scrolled to the bottom of the popup.

<div id="myModal" data-role="popup" data-position-to="window" data-history="false" data-theme="a" data-corners="true" class="ui-content" style="text-align:center">
    <div class="modal-dialog">
         <div class="modal-content">
             <div id='myModalContent'></div>

             <a href="#" id="closeButton" class="ui-btn ui-corner-all ui-shadow ui-btn-inline ui-btn-b">OK</a>
         </div>
    </div>
</div>   
$(".anchorDetail").click(function () {
    $("#myModal").scrollTop(0);
}
Paul Roub
  • 36,322
  • 27
  • 84
  • 93
Jon Roop
  • 31
  • 1
  • 8
  • 2
    Have you got a jsfiddle replicating your issue? – Kevin Lynch Jun 26 '17 at 20:26
  • 1
    Check this out? Might be something to try. https://stackoverflow.com/questions/6736849/scrolltop-not-working-in-ie – Sensoray Jun 26 '17 at 20:29
  • I have tried that out, Paige, and it doesn't even want to work in FF or Chrome. I have searched through as many questions I could on here. No jsfiddle, not quite yet. The rest of the JS that i didn't include pulls data back from an ajax call. – Jon Roop Jun 26 '17 at 20:40
  • 1
    Have you tried `$("#myModal")[0].scrollTop(0);`? Maybe... – Louys Patrice Bessette Jun 26 '17 at 21:50
  • 1
    you might wanna try [this cross-browser animation](https://stackoverflow.com/a/5580456/28004) to top instead... I use it in several projects with a nice go-to-top image that fades in and out when the user scrolls the page... – balexandre Jun 26 '17 at 22:03

2 Answers2

3

Try this, it's done with JS and not jQuery:

document.querySelector('.anchorDetail').addEventListener('click', function() {
var myDiv = document.getElementById('myModal');
myDiv.scrollTop = 0;
});
0

Thank you all for your suggestions.

I feel so so dumb.
I was having it attempt to scroll to the top before it populated the data and opened the popup.

I moved the .scrollTop() function to after i Open the popup, and VOILA.

Thank you all again.

Jon Roop
  • 31
  • 1
  • 8