僅計算子div
var divsNumber = $('.vc_tta-panels > div').length;
但是如果你想所有div,兒童和兒童....
var divsNumber = $('.vc_tta-panels div').length;
$(document).ready(function(){
var divsNumber = $('.vc_tta-panels > div').length;
console.log('Numbers: ' + divsNumber);
});
<script src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
<div class="vc_tta-panels">
<div class="vc_tta-panel"></div>
<div class="vc_tta-panel"></div>
<div class="vc_tta-panel"></div>
</div>
將它發送到另一個頁面,您可以使用查詢字符串:
var divsNumber = $('.vc_tta-panels > div').length;
window.location.href = ANOTHERPAGE.html?number=divsNumber;
而在另一個頁面獲得此數目:
<script>
(function ($)
{
$.QueryString = (function (a)
{
if (a == "") return {};
var b = {};
for (var i = 0; i < a.length; ++i)
{
var p = a[i].split('=');
if (p.length != 2) continue;
b[p[0]] = decodeURIComponent(p[1].replace(/\+/g, " "));
}
return b;
})(window.location.search.substr(1).split('&'))
})(jQuery);
var num = $.QueryString["number "];
$('.menu-item-4331').after().css('content', num);
</script>
謝謝,這正是我的意思 – CliffVandyck