How to apply onclick event to html tag when it displays in a loop
http://stackoverflow.com/questions/38119513/how-to-apply-onclick-event-to-html-tag-when-it-displays-in-a-loop
by dixalex
HTML
<div class='entries'>
mySQL 1
</div>
<div class='entries'>
mySQL 2
</div>
<div class='entries'>
mySQL 3
</div>
<div class='entries'>
mySQL 4
</div>
CSS
div {
width: 250px;
height: auto;
background-color: #ACE;
clear: both;
margin-bottom: 2px;
}
JavaScript
var $entryCollectionArray = $('div.entries')
$entryCollectionArray.click(function(i) {
var $brothers = $(this).siblings();
var $activeEntry = $(this);
$brothers.addClass('notActive').removeClass('active');
$activeEntry.addClass('active');
if ($activeEntry.addClass('active')) {
$activeEntry.animate({
height: '120px'
}, 550);
$brothers.animate({
height: '18px'
}, 550);
}
});