Created
March 24, 2021 09:14
-
-
Save Rameshwar-ghodke/25e2f911b68b23ad259f9989490bca27 to your computer and use it in GitHub Desktop.
Make it tree structure layout using HTML CSS and javascripti
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*====== CSS ======*/ | |
ul, #tree_list { list-style-type: none;} | |
#tree_list { margin: 0; padding: 0;} | |
#tree_list .box1 { cursor: pointer; | |
-webkit-user-select: none; /* Safari 3.1+ */ | |
-moz-user-select: none; /* Firefox 2+ */ | |
-ms-user-select: none; /* IE 10+ */ | |
user-select: none; } | |
#tree_list .box1::before { content: "\2610"; color: black; display: inline-block; margin-right: 6px;} | |
#tree_list .check-box::before { content: "\2611"; color: dodgerblue;} | |
.nested { display: none;} | |
.active { display: block;} | |
/*====== HTML ======*/ | |
<ul id="tree_list"> | |
<li><span class="box1">Beverages</span> | |
<ul class="nested"> | |
<li><span class="box1">Tea</span> | |
<ul class="nested"> | |
<li><span class="box1">Green Tea</span> | |
<ul class="nested"> | |
</ul> | |
</li> | |
</ul> | |
</li> | |
</ul> | |
</li> | |
</ul> | |
/*====== Script ======*/ | |
<script> | |
/* Tree structure related script */ | |
var toggler = document.getElementsByClassName("box1"); | |
var i; | |
for (i = 0; i < toggler.length; i++) { | |
toggler[i].addEventListener("click", function() { | |
this.parentElement.querySelector(".nested").classList.toggle("active"); | |
this.classList.toggle("check-box"); | |
}); | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment