You can use attribute value selector
[id^=subchild]selects all elements whose value idbegins with ( ^) child.
The attribute value begins with a selector.
Selects elements with the specified attribute with a value starting exactly with the given string.
Demo
$(function() {
var subchildrenLen = $('#parent [id^=subchild]').length;
$('body').append('No of children = ' + subchildrenLen);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<div id="parent">
<div id="child1">
<div id="subchild1"></div>
</div>
<div id="child2">
<div id="subchild2"></div>
</div>
<div id="child3">
<div id="subchild3"></div>
</div>
</div>
Run codeHide result
querySelectorAll , jQuery.
var subchildrens = document.querySelectorAll('#parent [id^=subchild]').length;
,
var allChildrens = document.querySelectorAll('#parent div').length