Chrome检查器中是否有一种方法可以生成dom选择器

时间:2012-12-07 16:11:07

标签: javascript asp.net google-chrome

我是否可以为我想在javascript中操作的html类生成选择器语句。当我尝试顶部时,我看到该类存在。$ find('。specific_class');它返回null,这让我相信我使用了错误的select语句。

2 个答案:

答案 0 :(得分:2)

您可以使用.length测试选择器是否存在 - 例如:

if($(".specific_class").length){
    //$(".specific_class") definitely exists, so now you can do something like:
    $(".specific_class").find(function(){
        //code
    });
}

答案 1 :(得分:1)

您的JQuery选择器格式不正确。

尝试以下方法:

$(".specific_class").find(function(){                  

       // do your code here with this instance of the found .specific_class $(this)

       // get this items ID
       var id = $(this).attr("id");


});
相关问题