I'm trying to make a blue background color to stay on the SVG icon that is active displaying the text using pure JavaScript. I'm also getting icons from semantic UI.
This is the code of the current menu list, and so far clg prints me the items inside for
:
HTML
<span class="menu-bar">
<a href="javascript:void(0)" class="itemList"> <svg><svg/> </a>
<a href="javascript:void(0)" class="itemList"> <svg><svg/> </a>
<a href="javascript:void(0)" class="itemList"> <svg><svg/> </a>
<a href="javascript:void(0)" class="itemList"> <svg><svg/> </a>
<i class="angle left icon iconColor tooltip" id="angle_icon"></i>
<i class="text height icon iconColor tooltip" id="measure_icon"></i>
</span>
CSS
.menu-bar {
display: block;
width: 100%;
height: 100%;
margin-top: -10px;
}
.menu-bar svg {
display: inline-block;
width: 1em;
padding: 0.3em;
border-radius: 4px;
margin-right: 20px;
}
.menu-bar a.toggle-state {
background-color: #1A41B5;
}
JavaScript code (so far)
function changeIndex(){
for (let i = 0; i <= items.length; i++) {
console.log(items[i])
}
}
I managed to fixed it with:
function _clearIcon() {
for (const icon of items) {
if(icon.classList.contains('menu-barActive')) {
icon.classList.remove('menu-barActive')
}
}
}
function changeIndex() {
for (const icon of items) {
icon.onclick=()=> {
_clearIcon()
let activeId = document.getElementById(icon.id)
activeId.classList.add('menu-barActive')
}
}