Is there any way to automatically scroll to the bottom when overflow-y is set to scroll and the height is defined

How can I scroll to the bottom of a container with overflow-y:scroll and height:100vh?

CSS

#content {
  height: 100vh;
  overflow-y: scroll;
}

JavaScript

var content = document.getElementById('content');
window.scrollTo(0, content.scrollHeight);

Here is the CodePen example: https://codepen.io/betchi/pen/zjBwgx

Answer №1

The scenario you provided involves scrolling the entire window. To achieve your desired outcome, you should scroll the content specifically, not the window as shown below:

content.scrollTo(0, content.scrollHeight);

Answer №2

Ensure to utilize the scrollTop property of the specific element you are looking to scroll.

Update your function with the following code snippet:

function unableToScroll(){
  var section = document.getElementById('section');
  section.scrollTop = section.scrollHeight;
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

"Create a set of arrays within an object that are duplicates four times, and then dynamically manipulate the first item within each array

Here is the layout of my array object: const foo = {"data":[ [1,'asdf'], [2,'lorem'], [3,'impsum'], [4,'test'], [5,'omg'], ]} I am looking to replicate each array four times and increment the first item ...

The issue arises when attempting to use the onChangeText function outside of the component and it fails to work

I am currently facing an issue with my test where the onChangeText function does not update the value of the TextInput component as expected. const TestComponent = ({onChangeText, value}) => { return (<TextInput testID={'input'} onChangeTex ...

What is causing my text to not appear in a single line?

Can someone help me figure out why my register and login options are overlapping? I'm pretty new to this so it might be a simple fix. Also, I'm trying to get the dropdown menu to appear right below the login text, but I'm facing some issues ...

The combination of jQuery keyUp and AJAX always seems to lag about 1 or 2 keystrokes behind

Creating a Twitter Instant Search tool was a fun project for me, where I used jQuery and PHP to make it happen. By linking the keyup event on the search form with an AJAX call to retrieve Twitter Search JSON data from a PHP page, I was able to display real ...

Implementing React selectors to manage the state changes on page load and when a user

I'm currently delving into React selectors with ReSelect, and while things seem to be going well, I have a feeling that there may be an issue in my logic. 1 - Upon receiving an AJAX response, I obtain a list of "categories" consisting of id, name, an ...

Display a loading message using jQuery Dialog when the page is loading

I have a button that triggers a jQuery Dialog box to open. $( "#dialog" ).dialog({ autoOpen: false, title: 'Contract', height: 450, width:1100, modal:true, resizable: true }); $( ".btnSend" ).click(function() { var id=$(this).a ...

CSS selector for detecting elements with empty or whitespace-only content

A special selector called :empty allows us to target elements that are entirely devoid of content: <p></p> However, in some cases, the element may appear empty due to line breaks or white spaces: <p> </p> In Firefox, a workar ...

Powerful button plugin designed for AngularJS Datatables

While using the angularjs datatable, I encountered an issue with the button plugin on this page .withButtons([ 'columnsToggle', 'colvis', 'copy', 'pdf', 'excel', { text: &a ...

How can I retrieve the checked values of checkboxes and store them in an array using React?

https://i.sstatic.net/jTRRU.png This toggle button is dynamically generated based on data, and I need to save the checked values in an array. Code {this.state.customersmsselect.map((e, key) => { if(e.isactive == "ON"){ return ( &l ...

Step-by-step guide on integrating Bulma page loader extension as a Vue component

Is there a way to integrate the Bulma-extension page-loader element as a Vue component in my project? I attempted to import page-loader.min.js and use it, but unfortunately, it didn't work as expected. <template> <div class="steps"> ...

Transferring a PHP session variable to JavaScript in a separate file

I successfully imported data from a CSV file into PHP and organized it into a nested array. To ensure the data is easily accessible across different files, I stored the array as a session variable. Now, the challenge lies in accessing this session variable ...

Using SASS to add class selectors in a loop

Can I achieve the desired CSS using SASS? .menu IMG { padding-left: 10px; } .menu .submenu IMG { padding-left: 20px; } .menu .submenu .submenu IMG { padding-left: 30px; } I need to add ".submenu" in each loop of the selector and update the padding accord ...

Having trouble implementing a custom font family in a React Native Text component

Struggling to integrate a custom font into my react native app, I've gone through various solutions from SO and Google but nothing seems to work. I attempted to inform react native about the font by adding "rnpm": { "assets": [ "./assets/fonts/" ...

The Front End API is unable to locate the Back End Endpoint

I am currently setting up an API call to test the functionality of my backend server. The front end is built using React, while the back end utilizes Node.js with express. The endpoint on the backend is quite simple: app.get('/', (req, res) => ...

A comparison between Angular JSON and JSONP $promise

When making a JSON call from my controller.js: $scope.userInvestors = userInvestors.query({UserID:$scope.user.uid}, function(userInvestors) { console.log("yep yer here"); } Using this $resource: factory('userInvestors', function($resour ...

Margin not being applied to last element in parent - any ideas why?

Why does the margin of the last element, whether it is a <p> or <h1>, not have any impact? It should be pushing the background of the parent container downwards. .container { background: grey; } h1 { margin-bottom: 3em } p { margin- ...

Is there a way for me to detect click events on Windows notifications?

Currently, I am attempting to send notifications through the node-notifier package. The goal is for a click on the notification to lead to a specific link. However, I am encountering difficulties in listening to the click event - the events provided by the ...

In the dragstart event handler, event.dataTransfer and event.originalEvent will consistently be null

I have been working on developing drag and drop directives for angularJS by referencing this informative post: However, I am facing an issue where the dataTransfer and originalEvent are consistently null within the dragstart event handler, preventing me f ...

Encountering an Unexpected : Token When Parsing JSON Arrays in AngularJS

I've been searching on various forums for an answer to my AngularJS issue without any luck. I have a simple controller that calls an http service and reads the response data, which is in JSON format with an objects array. However, I'm facing diff ...

Testing an Angular 2 component with simulated dependencies

Attempting to test an Angular 2 component with fake dependencies has been a challenge. Currently developing a simple TODO app using Ng2 and Redux, I have encountered a situation where one of my components includes an instance of the redux app store. In o ...