[javascript] Can't change z-index with JQuery

I, for some reason, can't change the zIndex of an element using jQuery. I've searched all of this website and Google but couldn't find the right answer. I am trying to put my element in front of another div when clicking a button. I used the code you can see under here. But didn't work.

  $(this).parent().css('zIndex',3000);

CSS code of elements it's under in the begin:

#wall{
    width:100%;
    height:700px;
    position: absolute;
    top:500px;
    background: #11c1e7;
    opacity: 0.6;
    z-index: 900;
    }

CSS code of element that should go above this:

.port1 {
width:200px;
height:200px;
left:<?php echo rand(1,1000); ?>px;
top:-500px;
border-radius: 500px;
background:red;
position:absolute;
z-index: 10;
}

Does anyone know how I can fix this?

// Edit

Link to the site: http://dannypostma.com/project/j.php

When clicking the portfolio ball, two balls drop from the air. These should go in front of the water when clicked.

This question is related to javascript jquery z-index

The answer is


Setting the style.zIndex property has no effect on non-positioned elements, that is, the element must be either absolutely positioned, relatively positioned, or fixed.

So I would try:

$(this).parent().css('position', 'relative');
$(this).parent().css('z-index', 3000);

because your jQuery code is wrong. Correctly would be:

var theParent = $(this).parent().get(0); 
$(theParent).css('z-index', 3000);

$(this).parent().css('z-index',3000);

zIndex is part of javaScript notation.(camelCase)
but jQuery.css uses same as CSS syntax.
so it is z-index.

you forgot .css("attr","value"). use ' or " in both, attr and val. so, .css("z-index","3000");


That's invalid Javascript syntax; a property name cannot have a -.

Use either zIndex or "z-index".


Examples related to javascript

need to add a class to an element How to make a variable accessible outside a function? Hide Signs that Meteor.js was Used How to create a showdown.js markdown extension Please help me convert this script to a simple image slider Highlight Anchor Links when user manually scrolls? Summing radio input values How to execute an action before close metro app WinJS javascript, for loop defines a dynamic variable name Getting all files in directory with ajax

Examples related to jquery

How to make a variable accessible outside a function? Jquery assiging class to th in a table Please help me convert this script to a simple image slider Highlight Anchor Links when user manually scrolls? Getting all files in directory with ajax Bootstrap 4 multiselect dropdown Cross-Origin Read Blocking (CORB) bootstrap 4 file input doesn't show the file name Jquery AJAX: No 'Access-Control-Allow-Origin' header is present on the requested resource how to remove json object key and value.?

Examples related to z-index

Bootstrap Modal sitting behind backdrop How to make a Div appear on top of everything else on the screen? Floating Div Over An Image How to use z-index in svg elements? How to make child element higher z-index than parent? Bring element to front using CSS z-index issue with twitter bootstrap dropdown menu How to "z-index" to make a menu always on top of the content Why does z-index not work? Can't change z-index with JQuery