javascript - How to change style of elements that aren't "(obj)" -
i have multiple items in row want change style of border based on selection.
here html of row , of 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 if !(obj).style....
. won't work , cannot find solutions anywhere.
i know how states , cases. however, didn't want js few 100 lines long.
so here js
var = 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"; } }
you can use js:
var imgs = document.getelementsbyclassname('item-img'); for(i=0; i<imgs.length; i++) { imgs[i].addeventlistener('click', function(){ (i=0; i<imgs.length; i++) imgs[i].style.border='1px solid blue'; this.style.border = '1px solid red'; }); }
Comments
Post a Comment