I have multiple items in a row that I want to easily change the style of the border based on my selection.
Here is the HTML of just the row and some of the items in it:
<div class="items">
<ul>
<li class="item-hold">
<span class="item icon64x64">
<img class="item-img icon64x64" src="css/img/3001.png" alt="Abyssal Scepter" id="as">
</span>
</li>
<li class="item-hold">
<span class="item icon64x64">
<img class="item-img icon64x64" src="css/img/3020.png" alt="Sorcerer's Shoes" id="ss">
</span>
</li>
<li class="item-hold">
<span class="item icon64x64">
<img class="item-img icon64x64" src="css/img/3025.png" alt="Iceborn Gauntlet" id="ig">
</span>
</li>
</ul>
</div>
I have tried to do if !(obj).style....
. However that won't work and I cannot find any solutions anywhere.
I Know how to do this with states and cases. However, I didn't want my JS to be a few 100 lines long.
So here is my js
var as = document.getElementById('as');
var ss = document.getElementById('ss');
var ig = document.getElementById('ig');
as.addEventListener('click', function() {
ItemDisc('as');
});
ss.addEventListener('click', function() {
ItemDisc('ss');
});
ig.addEventListener('click', function() {
ItemDisc('ig');
});
function ItemDisc(obj) {
var change = document.getElementById(obj);
var changeback = document.getElementById(!obj);
change.style.border = "5px solid blue";
for(!obj) {
changeback.style.border = "5px solid blue";
}
}