Here is my HTML:
<fieldset>
<legend>Ways I can be contacted</legend>
<div class="error-message-list"></div>
<div class="rows">
<div class="row">
<div>content</div>
<div>content</div>
</div>
<div class="row">
<div>content</div>
<div>content</div>
</div>
</div>
</fieldset>
<p><a id="count" href="#">Couynt</a></p>
..and here's my Jquery:
<script type="text/javascript">
$(document).on({
click: function(event) {
event.preventDefault();
console.log($(this).parents().siblings('fieldset .rows div.row').length);
}
},'#count');
</script>
When I click on "Count" a zero gets written to the console. I would expect this to be a 2 because there are 2 divs with the class of row
within the rows
div.
If I just do it on the fieldset, ie, like this:
console.log($(this).parents().siblings('fieldset').length);
Then it returns a 1 as I would expect.
I have also tried
console.log($(this).parents().siblings('fieldset .rows .row').length);
and
console.log($(this).parents().siblings('fieldset > div.rows > div.row').length);
..and many other combinations, but I just can't get it to say '2'!