我正在尝试在特定div中找到类名为component ui-draggable dropped
的div的数量。
以下是相应的HTML代码:
<div id="tabs-1" aria-expanded="true" aria-hidden="false">
<div class="drag-drop-box ui-droppable">
<div class="component ui-draggable dropped">
<div class="product-view" >
<a href="#"><span>C</span> us-east-1c</a>
</div>
</div><div class="component ui-draggable dropped">
<div class="product-view">
<a href="#"><span class="img-product">
<img alt="" src="img/product_item/1.png"></span> image-11</a>
</div>
</div>
</div>
</div>
这是相应的jQuery代码:
var getid = $('div[aria-hidden="false"]').attr('id');
var clone_nums = $('#'+getid + '> div ').find('.component ui-draggable dropped').length;
alert(clone_nums
但警告总是弹出零。任何人都可以指导我这里有什么问题吗?感谢
答案 0 :(得分:4)
试试这个:
$(document).ready(function(){
var getid = $('div[aria-hidden="false"]').attr('id');
var clone_nums = $('#'+getid + '> div ').find('.component.ui-draggable.dropped').length;
alert(clone_nums);
});
<强> DEMO 强>
或
$(document).ready(function(){
var clone_nums = $('div[aria-hidden="false"] > div').find('.component.ui-draggable.dropped').length;
alert(clone_nums);
});
答案 1 :(得分:1)
您可以使用.has()之类的
var $div = $('div[aria-hidden="false"]');
var clone_nums = $div.has('.component.ui-draggable.dropped').length;
aria-hidden="false"
component
ui-draggable
和dropped
答案 2 :(得分:1)
var clone_nums = $('div[aria-hidden="false"]').find('div.component.ui-draggable.dropped').length;
For an element with multiple classes join the name of classes using "."(class selector) between them and don't use spaces.