jquery.find()未找到类

jquery.find()未找到类,jquery,Jquery,我的html代码中有一部分如下所示: <div id="photo-list-container" class="row"> <div class="col-xs-4 col-md-3"> <div class="photo-gallery-holder mar-2x" data-toggle="modal" data-target=".bs-example-modal-lg" data-id="{{

我的html代码中有一部分如下所示:

 <div id="photo-list-container" class="row">
            <div class="col-xs-4 col-md-3">
                    <div class="photo-gallery-holder mar-2x" data-toggle="modal" data-target=".bs-example-modal-lg" data-id="{{ $photo->id }}" data-photo-filename="{{ $photo->id }}" data-tags="{{ htmlspecialchars(json_encode($photo->tags)) }}">
                        <img class="img-responsive" src="{{ $photo->thumb_url }}" alt="{{ $photo->title }}" />
                    </div>
            </div>
    </div>
它总是返回未找到。为什么呢?我正在搜索的div嵌套在照片列表容器中,可以吗

请帮忙。谢谢。

您已经使用了
#
对于id选择器,您必须使用
作为类选择器,如下所示

$('#photo-list-container').find('.photo-gallery-holder').each(function() {
...
});

将行
$(“#照片列表容器”).find(“#照片列表容器”).each(function(){
更改为
$(“#照片列表容器”).find(“.photo列表容器”).each(function(){

也就是说,将
“#”
更改为

#
表示通过id定位元素

(点)
表示通过类名确定目标

在此链接上查找更多jQuery选择器

后期编辑

使用
$('#照片列表容器.照片列表容器')。每个(函数(){

检查小提琴(“#照片列表容器”)

$。查找(“#照片列表容器”)
将在
#照片列表容器
内查找
#照片列表容器
。将找不到任何内容

除此之外,
id
应该始终是唯一的。因此在任何情况下都不需要
find
each

如果要查找父级
#照片列表容器中的所有
.photo gallery holder
,可以使用
find
。但我建议使用直接选择器

$('#photo-list-container').find('.photo-gallery-holder').each(function() {
    // ...
});

// or better
$('#photo-list-container .photo-gallery-holder').each(function() {
    // ...
});

您只需添加Id元素为的类,如下所示。 它将首先找到Id为的元素,然后查找类并从HTML中找到匹配的元素

$('#photo-list-container .photo-gallery-holder').each(function(a,b) {
        .....
});

抱歉,我的错误。这就是我正在使用的..我错误复制了该行。请查看我对javascript行的上次更新..我第一次错误复制了该行,请查看我对javascript行的上次更新..我第一次错误复制的是
id=“照片列表容器”
多次出现在您的文档中?正如我所写,
id
是唯一的!@EdwardMaidenThen没有问题,@EdwardMaiden请参见此处:请查看我上次更新的javascript行..我第一次复制了$('#照片列表conta‌​照片画廊‌​r')。每个(功能(a、b‌​) {----在您给定的html代码中为我工作–哦,谢谢。那么我猜又是f******g laravel的错了。不知怎么回事,$('#照片列表容器.照片库持有者')。每个(函数(a,b){----在您给定的html代码中为我工作检查这个小提琴
$('#photo-list-container').find('.photo-gallery-holder').each(function() {
    // ...
});

// or better
$('#photo-list-container .photo-gallery-holder').each(function() {
    // ...
});
$('#photo-list-container .photo-gallery-holder').each(function(a,b) {
        .....
});