-3

how do why make scroll bar at the bottom every time when loading pages. tell me immediately

This is javascript not working. please help me

#student_name{
    height:315px;
 }     
 <div id = "student_name">abc<br>abc<br>abc<br>abc<br>abc<br>abc<br>abc<br>abc<br>abc<br></div>

 var objDiv = document.getElementById("student_name");
 objDiv.scrollTop = objDiv.scrollHeight;
Meenesh Jain
  • 2,532
  • 2
  • 19
  • 29
  • 1
    It is a bit unclear what you mean. Do you want to scroll to the bottom of the div when the page loads? Also, saying "tell me immediately" will not get you faster answers - probably the reverse. – Anders Aug 10 '15 at 12:28
  • Perhaps have a look at this: http://stackoverflow.com/questions/270612/scroll-to-bottom-of-div – Anders Aug 10 '15 at 12:39
  • Make sure the JS is executed when the DOM is ready, for instance by using `onload`. – Anders Aug 10 '15 at 12:40

1 Answers1

1

What you need is two things first in css:

#student_name{ height:100px; overflow:auto;}

add a overflow property.

and in the markup you should not add spaces with the attributes id = "student_name", it should be:

id="student_name"

and js code is actually working.

var objDiv = document.getElementById("student_name");
objDiv.scrollTop = objDiv.scrollHeight;
#student_name{ height:100px; overflow:auto;}
<div id="student_name">abc<br>abc<br>abc<br>abc<br>abc<br>abc<br>abc<br>abc<br>abc<br></div>
Jai
  • 74,255
  • 12
  • 74
  • 103