I am trying to create a JavaScript function that loops through a variable number of iterations and dynamically generates HTML elements on the DOM / Webpage. Once the loop is complete, it populates the following div:
<div class="energyRowContainer" id="energyRowContainer">
</div>
The generated content looks like this:
<div class="energyRowContainer" id="energyRowContainer">
<div id="energyRow0" class="energyRow">
<div class="energyTypeHead"> 1.2.2012 </div><div class="energyUnitMWH"> 93 </div><div class="energyUnitT"> 174 </div><div class="energyUnitM3_1"> 6594 </div><div class="energyUnitM3_2"> 116 </div><div class="energyUnitM3_3"> 34162 </div><div class="energyUnitM3_4"> 2625 </div><div class="energyUnitM3_5"> 17886 </div> <div class="energyUnitM3_6"> 21 </div>
</div>
<div id="energyRow1" class="energyRow">
<div class="energyTypeHead"> 1.2.2012 </div><div class="energyUnitMWH"> 93 </div><div class="energyUnitT"> 174 </div><div class="energyUnitM3_1"> 6594 </div><div class="energyUnitM3_2"> 116 </div><div class="energyUnitM3_3"> 34162 </div><div class="energyUnitM3_4"> 2625 </div><div class="energyUnitM3_5"> 17886 </div> <div class="energyUnitM3_6"> 21 </div>
</div>
<div>
Now, I am looking for a way to change the background color of the entire row (with class="energyRow") using jQuery or CSS. Simply applying a energyRow:hover seems ineffective as hovering over child divs does not trigger the effect. I have attempted the following approach without success. Any suggestions or ideas are greatly appreciated!
$('#energyRowContainer > .energyRow, ').hover(function() {
$(this).parent().toggleClass('name_of_a_hover_class');
});