I want to add background images with javascript, I did with element.style.backgroundImage but I want to do Z-index on it, I know it doesn't work with background images so i want to do it with the order, I want to initialize it then add an image with a higher "z-index", here's my function:
function newBackGround (element,background, box) {
var current_image = element.style.backgroundImage;
if (current_image != ""){
if (box.type != "normal") {
element.style.backgroundImage = "url("http://placekitten.com/200/200")";
element.style.backgroundImage = "url("http://placekitten.com/500/200"), url("http://placekitten.com/2089/458")"; }
else{
element.style.backgroundImage = "url("+background+")";
}
}
else{
element.style.backgroundImage = "url("+background+")";
}
My HTML(very short):
<!DOCTYPE html>
<head>
<link rel='stylesheet' href="DouShouQui.css">
</head>
<body>
<table>
<tr>
<td></td>
</tr>
</table>
<script src="DouShouQui.js"></script>
</body>
and here's my css:
td {
border: 1px solid black;
width: min(calc(30vw), calc(30vh));
height: min(calc(10vw), calc(10vh));
background-color: black;
text-align: center;
color: #FF9800;
font-size: 100%;
background-size: contain;
background-position: center;
background-repeat: no-repeat;
position: relative;
}
Box.type is initialized somewhere. And i can't use specific classes because i have 21 images but if there's something you can do with a few classes and javascript it's good. In the result it puts nothing, both images are not showed.