Reputation: 131
I'm trying to learn jQuery...the syntax is confusing to me. Maybe what I am doing wrong is syntax related.
This line alerts a value of 36:
$(alert(('.htCore tbody tr th.ht_nestingParent').length));
When I do an inspect in the browser and CTRL+F I only find 6; not 36. So, I'm trying to loop through each one it finds and have it dump to console or alert the html values; this way I can try to figure out why it says 36 instead of 6.
Here is my loop I made...but it's not doing anything when I run it.
$(document).ready(function() {
$('.htCore tbody tr th.ht_nestingParent').each(function (i) {
$val = $(this).html;
alert($val);
});
});
Here is my HTML
<tbody>
<tr>
<th class="ht_nestingLevels ht_nestingParent"><div class="relative"><span class="rowHeader">1</span>
<div class="ht_nestingButton ht_nestingCollapse"></div>
</div></th>
<td class="">7-ELEVEN</td>
<td class="">22971161</td>
<td class=""></td>
<td class=""></td>
<td class=""></td>
<td class=""></td>
<td class=""></td>
</tr>
<tr>
<th class="ht_nestingLevels ht__highlight"><div class="relative"><span class="ht_nestingLevel_empty"></span><span class="rowHeader">2</span></div></th>
<td class="current highlight"></td>
<td class=""></td>
<td class="">A</td>
<td class="">SOUTH MOD 67 ID FACE||7-11 OKLAHOMA COLORS||95-5/8 X 96-3/4||DWG: SO1067RF.OK (102138)||</td>
<td class="">4</td>
<td class="">2020-02-20</td>
<td class="">2020-01-24</td>
</tr>
<tr>
<th class="ht_nestingLevels ht_nestingParent"><div class="relative"><span class="rowHeader">3</span>
<div class="ht_nestingButton ht_nestingCollapse"></div>
</div></th>
<td class="">7-ELEVEN</td>
<td class="">22983321</td>
<td class=""></td>
<td class=""></td>
<td class=""></td>
<td class=""></td>
<td class=""></td>
</tr>
</tbody>
My goal is to find those tags with a class of .ht_nestingParent and then add a blank table row above the .ht_nestingParent and then a blank row under the last of it's children rows; which are the rows below that lack the .ht_nestingParent class.
Upvotes: 0
Views: 49
Reputation: 7593
This line is not well written
$(alert(('.htCore tbody tr th.ht_nestingParent').length));
The 36 you receive is the number of character in this string .htCore tbody tr th.ht_nestingParent
because you're simply alerting the length of the string.
This should give you the correct number
alert($('.htCore tbody tr th.ht_nestingParent').length);
Upvotes: 1