I have 3 divs and 3 buttons. I want a javascript code for , if I click button1 then all the divs should be visible. if I click button2, then div2 should be visible only, and it should be infront of div1 and div3. if I click button3 , then div3 should be visible only , and it should be infront of both div2 and div3.
My code is bellow:
[<html>
<head></head>
<body>
<input type="button" id="button1" onclick="button1Click();"/>
<input type="button" id="button2" onclick="button2Click();"/>
<input type="button" id="button3" onclick="button3Click();"/>
<div id="id1">
<input type="checkbox" />
</div>
<div id="id2">
<input type="checkbox" />
</div>
<div id="id3">
<input type="checkbox" />
</div>
<script type="text/javascript">
function button1Click() {
var DivId1 = document.getElementById("id1");
var DivId2 = document.getElementById("id2");
var DivId3 = document.getElementById("id3");
DivId1.style.visibility = "visible";
DivId2.style.visibility = "visible";
DivId3.style.visibility = "visible";
}
function buttonClick2() {
var DivId1 = document.getElementById("id1");
var DivId2 = document.getElementById("id2");
var DivId3 = document.getElementById("id3");
DivId1.style.visibility = "hidden";
DivId2.style.visibility = "visible";
DivId3.style.visibility = "hidden";
}
function buttonClick3() {
var DivId1 = document.getElementById("id1");
var DivId2 = document.getElementById("id2");
var DivId3 = document.getElementById("id3");
DivId1.style.visibility = "hidden";
DivId2.style.visibility = "hidden";
DivId3.style.visibility = "visible";
}
</script>
</body>
</html>][1]
but this clickevent can only appears or disappers a div but cannot bring a div infront of other divs. As a result there is free space like the second pic infront of the div.
z-index
- w3schools.com/cssref/pr_pos_z-index.asp – Nick