Using JavaScript to display a hidden element when clicked within an overflow-auto container

I have a collection of items grouped within a container with overflow-auto applied.

When clicked, I want to scroll/place an item all the way to the right if possible. This will trigger the other items to auto-scroll to the left, positioning the clicked item at the end of the view.

for(let i = 1; i < 20; i++) {
  document.getElementById("parent").innerHTML += `<div class='myItem margin-end-3 d-flex flex-column justify-content-center align-items-center'>${i}</div>`;
}
.myItem {
  height: 30px;
  border-radius: 20px;
  background-color: gray;
  font-size: 15px;
  padding: 20px;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
  
<div id="parent" class="d-flex flex-row flex-nowrap overflow-auto my-18 py-1"></div>

For Instance:

Initial State:

https://i.sstatic.net/GHuaU.png

After Clicking "13":

https://i.sstatic.net/GGEbf.png

Answer №1

Here is how the problem was resolved:

You can fix it by attaching a click event listener to the elements and invoking

event.currentTarget.scrollIntoView()
.

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

Display full lines of nested tree view HTML lists upon hovering using HTML, CSS, Angular, and Bootstrap

I currently have an Angular 4 application where a left-side div displays a tree of items as recursive HTML lists. The issue I am facing is that long texts within this div get cut off by the right border, with a scrollbar appearing instead. What I would lik ...

Launch a new tab within the parent window, passing on variables from the parent window

Currently, I have a button that opens a new window in a new tab by using window.open("newpage.html"). In the child window, I use childVar = window.opener.parentGlobalVar to access global variables from the parent window. Now, I have been requested to open ...

The CSS selector within the website's URL

When a URL like www.example.com/#signup is entered, the browser focuses its view on the HTML element with the ID signup. Is this correct? Can the CSS style of the element be changed if it is focused in this way? For example, if there is a div element wit ...

Having issues with Tailwind classes not being applied properly on dynamically generated pages in Gatsby-node

Currently, I am working on building dynamic pages using gatsby-node. The templates for these pages are stored in the templates/ directory. However, I have run into an issue where I cannot utilize tailwind classes within these templates unless they are al ...

Stop the back button from closing the Cordova application

I've encountered a persistent issue in my cordova application where the back button consistently exits the app, regardless of any attempted solutions. I have diligently searched for answers online and tested various strategies, but none have proven su ...

Using a Javascript loop to showcase values from a database

As a Python developer who is new to JavaScript and AJAX, I am currently working on creating a pie chart that displays database values. $(document).ready(function () { google.charts.load('current', { 'packages': ['corechart&ap ...

Adjust the background hue within PNotify

I've integrated the Porto Admin Theme into my website, which can be found at This theme utilizes PNotify for notifications, available at: I'm looking to customize the notification colors in a light pastel scheme when choosing "Bootstrap 4" or B ...

Reduce the height of a single column in Bootstrap

My goal is to create a footer design using Bootstrap that looks like this: https://i.sstatic.net/7xsKg.png I've successfully set up the left column (Red Background) of the footer, but I'm having trouble styling the right column (Black Backgroun ...

AJAX: Building a Robust Single Page Application with Enhanced Security

Currently, I am developing a web/mobile application using AJAX. This app consists of 4 pages: the login page and three protected pages that are only accessible to logged-in users. My plan is to implement the Single Page Application pattern, where all 4 pa ...

Set the property state to false based on the value of another property in Mongoose Express NodeJS

I am trying to update the status property of a sale based on the outstandingBalance value being equal to 0. Currently, I am able to successfully update the "outstandingBalance", but I want to automatically change the status if it reaches 0. Below is the c ...

Node.js Error: (Headers already sent, cannot be modified)

My goal in the program is to utilize both res.send and render simultaneously with the same data. I have a Qt application that can receive the data from my Node JS, but it appears challenging to send and render the data on the webpage at the same time. - ...

Automatically closing the AppDateTimePicker modal in Vuexy theme after selecting a date

I am currently developing a Vue.js application using the Vuexy theme. One issue I have encountered is with a datetimepicker within a modal. The problem arises when I try to select a date on the datetimepicker component - it closes the modal instead of stay ...

Utilizing transitions to control the visibility of div elements

This is what I have achieved so far: function getOffsetRect(elem) { var box = elem.getBoundingClientRect() var body = document.body var docElem = document.documentElement var scrollTop = window.pageYOffset || docElem.scrollTop || body.sc ...

"Using Mongoose to push objects into an array in a Node.js environment

I am faced with a peculiar issue involving an array of images in my code. Here is the structure: var newImageParams = [ { image_string: "hello", _type: "NORMAL" }, { image_string: "hello", _type: "NORMAL" } ] M ...

Encountered a MultiValueDictKeyError in Django at /employeeUpdate/ after making changes to the data

Encountering a django error "MultiValueDictKeyError at /employeeUpdate/ 'id'" after making changes to the data. Here is the code snippet from my views.py: def employeeUpdate(request): id = request.POST['id'] emp_username = requ ...

By utilizing the power of JSONP, data transfer limitations can be eliminated

Is it possible to remove the limitation on data sent using JSONP? Here's my code. I'm attempting to send 3000 characters (an image converted to base64 data) at a time to a service (serviceCall.ashx). Since my data is quite large, up to 30,000-40, ...

My website is currently being hosted on Github, but I am experiencing issues with the CSS. I keep getting an error message saying "Failed to load resource: the server responded

view image here I recently uploaded my website on Github and am facing an issue with the CSS file not working properly. Can someone please help me troubleshoot this problem? website link Github repository I have reviewed the links connecting the HTML t ...

Steps for sending a POST request for every file in the given array

I am working on an angular component that contains an array of drag'n'dropped files. My goal is to make a POST request to http://some.url for each file in the array. Here is what I have been attempting: drop.component.ts public drop(event) { ...

Tips for eliminating the page URL when printing a page using window.print() in JavaScript or Angular 4

Can someone help me with a function that uses window.print() to print the current page, but I need to remove the page URL when printing? I'm looking to exclude the URL from being printed and here is the code snippet where I want to make this adjustme ...

Having issues with incorporating a component into another component in VueJS

Having spent approximately 30 hours on diving into VueJS, I am encountering some difficulties when it comes to using a component within another component. Seeking assistance from someone knowledgeable in this area to provide me with some clarification. Pr ...