简单的jQuery选择器只选择Chrome中的第一个元素..? [英] Simple jQuery selector only selects first element in Chrome..?
问题描述
我对jQuery有点新,所以请原谅我的密度。我想通过Chrome的JS控制台在特定页面上选择所有< td>
元素:
$('td')
然而当我这样做时,以下输出:
< td>苹果< / td>
不是jQuery应该返回< td>
标签?为什么我只看到符合此标准的第一个元素?
以下是有问题的网站: http://www.w3schools.com/html/html_tables.asp
编辑:我想补充一点当我在Chrome控制台中键入jQuery函数时,我没有收到一个jQuery对象。我得到一个普通的HTML元素。 Chrome浏览器设置/配置的方式肯定是错误的。
解决方案如果jQuery不在网页上,当然没有其他代码为 $
分配内容,Chrome的JS控制台会为<$ c $分配 $
快捷键c> document.querySelector()。
你可以通过 $$()
,它由控制台分配给 document.querySelectorAll()
的快捷方式。
要知道如果页面包含jQuery,则可以在控制台中执行 jQuery
。要知道jQuery是否被分配给 $
,你可以执行 $()。jquery
这种情况。
此外,还有浏览器插件可以在每个网页中插入jQuery。
I'm a bit new to jQuery so forgive me for being dense. I want to select all <td>
elements on a particular page via Chrome's JS console:
$('td')
Yet when I do this, I get the following output:
<td>Apples</td>
Isn't jQuery supposed to return an array of elements with the <td>
tag? Why am I only seeing the first element that matches this criteria?
Here is the site in question: http://www.w3schools.com/html/html_tables.asp
EDIT: I'd like to add that when I type a jQuery function into Chrome console, I do NOT get a jQuery object back. I get a plain HTML element. Something must be wrong with the way my Chrome is set-up/configured.
If jQuery isn't present on the webpage, and of course no other code assigns something to $
, Chrome's JS console assigns $
a shortcut to document.querySelector()
.
You can achieve what you want with $$()
, which is assigned by the console a shortcut to document.querySelectorAll()
.
To know if the page contains jQuery, you can execute jQuery
in the console. To know if jQuery is assigned to $
, you can execute $().jquery
which will return jQuery version if that's the case.
Also, there are browser addons to inject jQuery in every webpage.
这篇关于简单的jQuery选择器只选择Chrome中的第一个元素..?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!