I have 3 divs:
I would like remove the blue background in <h4> if I click in the next ou prev div.
I would like insert a class into my <i class="fa fa-lg fa-gamepad"></i> if <h4> has blue blackground (above).
but if I just click in the icon <i> the icon color change for that specific div.
I hope i did make that clear.
html:
<div class="box"><i class="fa fa-lg fa-gamepad"></i><h4>div 1 </h4></div> <div class="box"><i class="fa fa-lg fa-gamepad"></i><h4>div 2 </h4></div> <div class="box"><i class="fa fa-lg fa-gamepad"></i><h4>div 3</h4></div> js:
$(document).ready(function() { var $box = $('.box').mousedown(function() { $('h4',this).toggleClass('highlight'); var flag = $(this).hasClass('highlight') $box.on('mouseenter.highlight', function() { $('h4',this).toggleClass('highlight', flag); }); }); $(document).mouseup(function() { $box.off('mouseenter.highlight') }) }); css:
.box { float: left; height: 100px; width: 100px; border: 1px solid #000; margin-right: 10px; } .highlight { background: #0000FF; } .fa-gamepad { color: red; }