Skip to main content
WolfShade
Legend
June 11, 2019
Answered

jQuery .load() automatically scrolls to element

  • June 11, 2019
  • 2 replies
  • 498 views

Hello, all,

I'm using jQuery .load() to refresh a CAPTCHA, and for some reason every time the refresh is done the page will scroll up.

<div id="captcha">

     <cfinclude template="hmntst.cfm"/>

</div>

...

$('#refresh').css({'cursor':'pointer'})

     .click(function(){

          $('#captcha').html("Working.."); /* if the CAPTCHA is slow to reload */

          $('#captcha').load('hmntst.cfm');/* This is a CF CAPTCHA */

          });

Any thoughts?

V/r,

^ _ ^

This topic has been closed for replies.
Correct answer WolfShade

by the way do you have any scrolling function associated to the page ?


You can't see it, but right now I'm facepalming myself.  Can't believe how simple this was.

<div id="captcha" style="height: 240px;"><cfinclude template="hmntst.cfm"/></div>

SMH,

^ _ ^

2 replies

Legend
June 11, 2019

Have you added return false to the click function?

Just a stab in the dark

B i r n o u
Legend
June 11, 2019

perhaps that the TAG having the 'refresh' id has a href pointing to a #... so if this is the case add a return false at the end of your click function

WolfShade
WolfShadeAuthor
Legend
June 11, 2019

There is no href on the 'refresh' element.

<span id="refresh" class="refresh-btn">

    <img src="images/refresh.png" alt="Having trouble reading? Click to refresh." style="width: 20px; height: 20px; padding: 10px;" title="Having trouble reading? Click to refresh.">

</span> Click to refresh CAPTCHA image.

V/r,

^ _ ^

B i r n o u
Legend
June 11, 2019

it's an inline TAG, what is wrapping it ? and what is wrapping the nested Block is any ?

does using the return false, still produce the same result ?