When I click on x inside the closing div, I want the background to change to white.
This is the markup:
<div class="list-item list-item-active"> <div class="close">x</div> </div>
This is javascript:
$(document).ready(function(){ $('.list-item').live('click', function() { if (!$(this).hasClass('list-item-active')) $(this).addClass('list-item-active'); }); $('.list-item .close').live('click', function() { $(this).parent().removeClass('list-item-active'); }); });
This is css:
.list-item {width:100px;height:100px;background:#fff} .list-item-active {background:#ccc}
Demo: http://jsfiddle.net/JMeff/
source share