I'm struggling to grasp the concept of jQuery (v1.11) when it comes to events and how DOM interaction impacts those events.
The scenario:
I am creating a grid of inline-blocks with the class "letter" and listening for clicks:
$('.letter).on('click',function(){ // do something })
Upon clicking one, it expands to fit the size of its parent container.
The issue:
Even after removing the class "letter", the div continues to respond to click events. Ideally, I want the div to expand to display more information, then shrink back into place once the user is finished.
Below is my html and the fiddle can be found at the end of this post.
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Test</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<style type="text/css">
/* apply a natural box layout model to all elements */
*, *:before, *:after {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
.square {
font-size: 20px;
color: white;
padding: 5px;
display: inline-block;
background-color: #69f;
height: 50px;
width: 50px;
vertical-align: top;
}
.grid {
width: 390px;
padding: 5px;
}
.row { padding-top: 5px; }
.square.empty { background-color: #87afff; }
.square-highlight { background-color: #36f; }
</style>
</head>
<body>
<!-- begin content -->
<div class="grid">
<div class="rows">
<div class="row">
<div class="square empty"></div>
<div class="square empty"></div>
<div class="square empty"></div>
<div class="square empty"></div>
<div class="square empty"></div>
<div class="square empty"></div>
<div class="square letter">a</div>
</div>
<div class="row">
<div class="square letter">b></div>
<div class="square letter">c></div>
<div class="square letter">d></div>
...
</html>
Access the fiddle here: http://jsfiddle.net/aKpLQ/