Manipulating zIndex using a Function does not produce the desired outcome

As I attempt to adjust the zIndex of the Div Boxes so that the targeted Div Box follows the mouse cursor and all surrounding Div Boxes move behind it, an issue arises where the zIndex remains unchanged resulting in the next Div Box overlapping the previous one.

The current approach involves changing the zIndex to 1 on mouseover and -1 on mouseout.

Your assistance with this matter would be greatly appreciated. Thank you for your help in advance.

function chartOuterDivScaleMax(i) {

    var a = document.getElementsByClassName('chartouterdiv');
    var b = document.getElementsByClassName('logocontainer');
    var c = document.getElementsByClassName('highdiv');
    var d = document.getElementsByClassName('lowdiv');

    a[i].style.transform = "scale(1.25)";
    a[i].style.zIndex = 1;

    b[i].style.transform = "scale(1.25)";
    b[i].style.transform = "translate(0px, 10px)";
    b[i].style.zIndex = 1;

    c[i].style.height = "70px";
    c[i].style.zIndex = 1;

    d[i].style.height = "35px";
    d[i].style.zIndex = 1;



}

function chartOuterDivScaleMin(i) {

    var a = document.getElementsByClassName('chartouterdiv');
    var b = document.getElementsByClassName('logocontainer');
    var c = document.getElementsByClassName('highdiv');
    var d = document.getElementsByClassName('lowdiv');

    a[i].style.transform = "scale(1)";
    a[i].style.zIndex = -1;

    b[i].style.transform = "scale(1)";
    b[i].style.zIndex = -1;

    c[i].style.height = "55px";
    c[i].style.zIndex = -1;

    d[i].style.height = "50px";
    d[i].style.zIndex = -1;


}

function iterateScaleFunction() {

    var elements = document.getElementsByClassName("chartouterdiv");

    for (let i = 0; i <= elements.length; i++ ){

        elements[i].addEventListener("mouseover", function() {chartOuterDivScaleMax(i)}, false);
        elements[i].addEventListener("mouseout", function() {chartOuterDivScaleMin(i)}, false);
    }
}
.chartouterdiv{
    height:115px;
    width:215px;
    background-color: black;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: 0.5s;
    transform: scale(1);
    margin-top: 10px;
    margin-bottom: 10px;
    float: left;
    z-index: 0;
}

.chartinnerdiv{
    height: 105px;
    width: 205px;
    background-color: white;
    transform: scale(1);
    z-index: 0;

}

.highdiv{
    height: 55px;
    width: 205px;
    background-color: antiquewhite;
    transition: 0.5s;
    transform: scale(1);
    z-index: 0;


}

.lowdiv{
    height: 50px;
    width: 205p;
    background-color: darkgrey;
    display: flex;
    align-items:center;
    justify-content: center;
    transition: 0.5s;
    transform: scale(1);
    z-index: 0;

}

.logocontainer{
    height: 50px;
    width: 50px;
    background-color: aquamarine;
    transition: 0.5s;
    transform: scale(1);
    z-index: 0;


}
<?php
    $i = 1;
    while($i <= 30) {    

        echo'<div class="chartouterdiv">';
        echo'<div class="chartinnerdiv">';                 
        echo'<div class="highdiv">';
        echo'</div>';
        echo'<div class="lowdiv">';
        echo'<div class="logocontainer">';
        echo'</div>'; 
        echo'</div>';
        echo'</div>';
        echo'</div>';

        $i++;                    
    };

Answer №2

Imagine you have a div with the class of "abc". If you want to adjust the z-index of that specific div, you can do so using the following:

document.getElementById("abc").style.zIndex = "1";

document.getElementById("abc").style.zIndex = "10";

You can set whatever z-index value you require.

For more information, check out this resource: https://www.w3schools.com/jsref/prop_style_zindex.asp

If I misinterpreted the question, please leave a comment or reply so I can better understand it. Thank you.

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

Using PHP to encode JSON and submit it via POST request

Issue: I am encountering difficulty in sending a JSON-encoded variable to a PHP page using jQuery/AJAX. Here is my current approach. The file is uploaded through It undergoes processing using jQuery based on the following JS code. JS code: <scrip ...

Using SVG graphics as data labels in a HighChart stacked column chart

I am attempting to generate a stacked column chart in Highcharts with SVG images as x-axis labels, similar to the image displayed here: https://i.stack.imgur.com/y5gL1.png I have managed to achieve this with individual data points per label (non-stacked ...

Tips for altering the appearance of the material-ui slider thumb design when it is in a disabled state

Through the use of withStyles, I have successfully customized the style of the Slider: const CustomSlider = withStyles(theme => ({ disabled: { color: theme.palette.primary.main }, thumb: { height: 24, width: 24, }, }))(Slider); How ...

Updating the value within a nested array in a ReactJS application

Check out the working code here: https://codesandbox.io/s/broken-https-2i454?file=/src/App.js I'm currently using Material UI within my reactjs project and facing an issue updating the value entered in a textfield of a table using the onChange functi ...

I am encountering problems with converting Array to JSON format in PHP for utilization in Javascript

I always face challenges when it comes to converting Array into JSON format. Currently, I am utilizing a selectbox plugin developed by TexoTela. For this plugin to work, it requires a specific JSON structure as shown below: { "ajax1": "AJAX option 1 ...

Personalized style for text overflow property

The application is created using Angular. Within a component, we have a div containing some text: <div>abcdefghijklmnop<div> Depending on the screen size, the text should either be fully displayed or clipped. I discovered the property 'te ...

Tips for achieving fluid and seamless page scrolling on a website

Looking to add smooth scrolling to my website but unsure of the best method - whether to override normal mouse scrolling or pursue another approach. I'm aiming for a similar effect as seen here. Give it a try and scroll through the page. ...

Troubleshooting AngularJS Directives' Cross-Origin Problems within Eclipse

Hello, I am facing an issue while using Angular JS in Eclipse. Specifically, when attempting to use Directives, I encounter a problem with the Cross-Origin Resource Sharing (CORS) policy when loading the Directives template in the index.html file. XMLHttp ...

Configuring Google Chart LineChart settings by utilizing the series attribute

I am looking to modify the options for my line chart. However, when I define the options as shown below, the first series setting gets ignored and only the second series property is applied. var options = { title: 'Temperature Graph ( sampling ev ...

The height of each Bootstrap column is equal to the height of its corresponding

I am trying to prevent the column height from being equal to the row height in Bootstrap. Here is my code snippet: <div class="row justify-content-center text-center"> <div class="col-sm-3"></div> <div class="col-sm-9"></d ...

An issue encountered with getServerSideProps in NextJS 12 is causing a HttpError stating that cookies are not iterable, leading

Currently, I have an application running smoothly on my localhost. However, when it comes to production, an unexpected error has popped up: Error: HttpError: cookies is not iterable at handleError (/usr/src/.next/server/chunks/6830.js:163:11) at sendReques ...

The mobile device isn't compatible with Jquery's "read more" feature

Recently, I've encountered some difficulties with the code below. It functions perfectly on desktop but fails to display correctly on mobile devices, showing the entire text instead. Take a look at the HTML section of the code: <span class="more" ...

Angular static dropdown option

<input [formControl]="twitterHandle" id="twitterHandle" placeholder="twitterHandle"> Fetching the input value from the Twitter handle input field using the following code: twitterHandle = new FormControl(); this.twitterHandle.value; Similarly, if ...

When working in React, I encountered a problem with the for of loop, as it returned an error stating "x is undefined." Although I could easily switch to using a simple for loop, I find the for of loop to

I'm encountering an issue when using a for of loop in React, as it gives me an error stating that "x is undefined". import { useEffect } from "react"; export default function HomeContent() { useEffect(() => { let content = document ...

Next.js API Endpoint Call Resulting in Empty Object Returned by Fetch Function

Having an issue with making an API call in Next.js to delete an item from the database. I'm using the "body" field of the fetch to send a string to the API. The fetch call is within a Next.JS page, and the API endpoint is located in the API folder gen ...

React Foundation accordion not functioning properly

Utilizing Foundation accordion within my React component has presented a challenge. The code functions properly when rendering static HTML, but when attempting to render it dynamically through a loop, the accordions lose their clickability. React code fo ...

Is there a way to send my form via the submission button inside a modal in ASP.NET MVC?

Although it may seem like a simple question to some, I am struggling with understanding how to implement a submit button that opens a modal and displays user input from a text box. The user can then choose to edit their input or proceed with submitting it. ...

Unable to hear sound - JavaScript glitch

Spent countless hours trying to figure this out - Can't get the audio file to play when clicking an HTML element. var sound = document.querySelector(".soundfile"); function playAudio() { sound.play(); } document.querySelector(".btn-hold").addE ...

Tips for dynamically adjusting the size of a div container according to the user's

I have been working on a unique landing page design featuring a menu made up of custom hexagons. I aim to make these hexagons dynamically adjust to fill the entire screen based on the user's resolution, eliminating the need for scrolling. For a previ ...

AngularJS - ng-repeat and bind do not automatically update when new data is added to an array

As a newcomer to AngularJS, I have come across conflicting information regarding ng-bind and its relationship with updating the output when the data source array changes. While some suggest calling $scope.apply() is necessary, others claim that using ng-re ...