javascript - Can i add class to a different element of hover with jquery/js -
i have mutable elements different id , want match id name class on tag toggle class tag`
<a id="ab" href="" class="divone marker"><span>this ab</span></a> <a id="aba" href="" class="divtwo marker"><span>this aba</span></a> <a id="abab" href="" class="divthree marker"><span>this abab</span></a> <div id="divone"></div> <div id="divtwo"></div> <div id="divthree"></div>
when hover on div gets id matches class on tag , adds class active , when remover hover removes class
i hope makes sense , appreciated
thanks in advance dan
you can use jquery.hover()
http://jsfiddle.net/4snhdpx1/6/
$('div').hover(function(event) { if (event.type == 'mouseenter') { $('.' + this.id).addclass('active'); } else { $('.' + this.id).removeclass('active'); } });
and fun can use shorter code :)
http://jsfiddle.net/4snhdpx1/8/
$('div').hover(function(e) { $('.' + this.id)[e.type == 'mouseenter' ? 'addclass' : 'removeclass']('active'); })
Comments
Post a Comment