0

When i click on a radio button, a new div, "resultat3" shown.

I want an automatic scroll down to the new div, when it is loaded.

function stateChanged7()
{
  if (xmlhttp.readyState==4)
   {
     document.getElementById("resultat3").innerHTML=xmlhttp.responseText;
     document.getElementById("show").innerHTML = showDiv4(1);
   }
}

Does anyone know how I can solve it?

HaveNoDisplayName
  • 8,291
  • 106
  • 37
  • 47
Andreas
  • 121
  • 2
  • 4
  • 10

3 Answers3

1
$('#html,body').animate({
  scrollTop: $("#resultat3").offset().top
});

Very similar to this already answered question. Hope it helps.

jQuery Scroll to Div

Community
  • 1
  • 1
Ben P
  • 23
  • 5
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. – Tim Lewis Mar 27 '15 at 14:20
  • That makes sense, apologies :) – Ben P Mar 27 '15 at 14:27
  • No problem. If you add more information from the link to your question, chances are it won't be flagged as low-quality and possibly removed. – Tim Lewis Mar 27 '15 at 14:28
  • If using jQuery, do it this way. It will scroll smoothly to your div. – Sully Mar 27 '15 at 14:50
0

you can do it by jquery .focus() method

Suppose your new div have id show then after putting data you can use,

$(window).scrollTop($('#show').offset().top);

It will focus or scroll to new div.

Pratik
  • 944
  • 4
  • 20
  • 1
    If you need scroll down to focus for div you can use above code. i have edited the answer, you can check this. – Pratik Mar 28 '15 at 15:51
0

I would try this:

function stateChanged6()
{
  if (xmlhttp.readyState==4)
  {
    document.getElementById("resultat2").innerHTML=xmlhttp.responseText;
    document.getElementById("show").innerHTML = showDiv4(1);
    $("#resultat2").focus();
  }
}

tested with:

$("resultat2").focus();
juco
  • 6,331
  • 3
  • 25
  • 42
Andreas
  • 121
  • 2
  • 4
  • 10