Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/385.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何通过其他任意标识符搜索没有ID的HTML元素?_Javascript_Html_Dom_Css Selectors - Fatal编程技术网

Javascript 如何通过其他任意标识符搜索没有ID的HTML元素?

Javascript 如何通过其他任意标识符搜索没有ID的HTML元素?,javascript,html,dom,css-selectors,Javascript,Html,Dom,Css Selectors,基本上,我试图在HTML文档中找到这个元素。我不知道该怎么做,因为没有ID,而且我对DOM的东西也比较陌生。有人知道怎么找到这篇文章吗 <strong ng-bind-html="gamePin" data-functional-selector="game-pin" class="ng-binding">6969696</strong> 696 您可以使用标记名和属性选择器,document.querySelector()或docume

基本上,我试图在HTML文档中找到这个元素。我不知道该怎么做,因为没有ID,而且我对DOM的东西也比较陌生。有人知道怎么找到这篇文章吗

<strong ng-bind-html="gamePin" 
       data-functional-selector="game-pin" 
       class="ng-binding">6969696</strong>
696

您可以使用标记名和属性选择器,
document.querySelector()
document.queryselectoral()


下面的代码应该可以工作

$( "div:contains('6969696')" )

区别此元素与其他元素的具体标准是什么?您是否查看了jQuery文档中的属性选择器?Google“jQuery选择器”请不要将文本作为图像发布。对不起,@m69。我并不经常使用这个网站。我认为假设这个元素是整个文档中唯一的或第一个.ng绑定是不合理的。我个人并没有在我正在进行的项目中使用jQuery,我只需要解析这个页面,不过谢谢你的帮助@Patrick Kenny:等等,如果你没有使用jQuery,为什么要将你的问题标记为[jQuery]?如果你没有使用jQuery,请找到解决这个问题的方法。@Patrick Kenny:啊,好的。jQuery借鉴了CSS标准,这也是选择器的来源。因此,您需要的不是jQuery选择器,而是CSS选择器。jQuery只是一个实现选择器的库(尤其是以非标准的方式)。我会重新回答你的问题。太好了。谢谢
let selector = "strong[ng-bind-html='gamePin'][data-functional-selector='game-pin'][class='ng-binding']";
let el = document.querySelector(selector);
$( "div:contains('6969696')" )