element.getElementsByClassName(""):

返回的含有该类的子元素数组,除了子元素以外的后代元素是获取不到的。要遍历使用,或者.element.getElementsByClassName("")[0]; 这样的方式获取元素。

document.getElementsByClassName:

这个才会返回含有该类的后代元素。

见MDN对element.getElementsByClassName()的定义:

中文版:

Element.getElementsByClassName() 方法返回一个即时更新的(live) HTMLCollection,包含了所有拥有指定 class 的子元素

当在 document 对象上调用此方法时,会检索整个文档,包括根元素。

相似地,getElementsByClassName() 方法会在整个文档上执行;它返回指定拥有指定 class 名称的 document 根节点的后代元素

英文版本:

The Element method getElementsByClassName() returns a live HTMLCollection which contains every descendant element which has the specified class name or names.

The method getElementsByClassName() on the Document interface works essentially the same way, except it acts on the entire document, starting at the document root.

注:英文版中的descendant是后代的意思,也就是说element.getElementsByClassName("");获取的含有该类名的后代元素,可是这样会报错。

西班牙语版:

El método Element.getElementsByClassName() retorna una HTMLCollection "viva" conteniendo todos los elementos hijos que tienen todos los nombres de clase dados. Cuando se llama en el objeto document, se realiza la búsqueda en el documento completo, incluyendo el nodo raíz.

De forma similar, el método Document.getElementsByClassName() actúa en todo el documento; retornará los elementos que sean descendientes del documento raiz especificado que tengan los nombres de clase dados.

注:hijos在西语中意思是儿子,返回的是子元素,descendientes,后代的意思。

法语版:

La méthode Element.getElementsByClassName() retourne une HTMLCollectioncontenant une référence sur tous les éléments ayant les noms de classes passés en paramètre. Quand la méthode est appelée sur l'objet document, la recherche s'effectue dans le document complet, noeud racine compris.

À l'instar de la méthode Document.getElementsByClassName() qui agit sur le document entier ; elle va retourner les descendants de l'élément spécifié comme document root qui auront les noms de classes passés en paramètre.

注: tous les éléments ayant,全部的含该类名的元素。也没有说明是子元素还是后代元素,传说中法语得的严谨呢?

日语版:

The Element.getElementsByClassName() メソッドは、引数で与えられたクラス名を含む全ての 子要素を ライブな HTMLCollectionで返します。 documentオブジェクトで呼ばれたとき、ルートノートを含む全ドキュメントが検索されます。

同様に、Document.getElementsByClassName() メソッドはドキュメント全体に働きます。特定されたドキュメントルート要素の子孫のうち、与えられたクラス名に合う複数のelementを返します。

注:日语也指明了是子元素。

俄语版:

Element.getElementsByClassName() метод возвращает объект HTMLCollection, содержащий в себе все дочерние элементы, которые имеют заданные имена классов. Если вызван на объекте document, будут возвращены все элементы, содержащиеся в документе.

Так же, как метод Document.getElementsByClassName() действует на весь документ; это вернет элементы, которые являются потомками корневого элемента, содержащие в себе указанные классы.

注:дочерние элементы 谷歌把它翻译为child node子元素而不是descandants后代元素。

总结:

五局三胜

Element.getElementsByClassName() 返回的是含有该类名的所有子元素集合。

Document.getElementsByClassName() 返回的是含有该类名的后代元素集合。

"getElementsByClassName is not a function" 报错原因的更多相关文章

  1. VMware报错“原因: 未能锁定文件”,打开失败

    原文:http://jingyan.baidu.com/article/425e69e6bf64dbbe15fc16fe.html VMware打开复制的虚拟机,报错“原因: 未能锁定文件”,打开失败 ...

  2. 查看报错原因 sshd -t

    b for ssh.service failed because the control process exited with error code. See "systemctl sta ...

  3. @Autowired报错原因分析和4种解决方案!

    上图的报错信息相信大部分程序员都遇到过,奇怪的是虽然代码报错,但丝毫不影响程序的正常执行,也就是虽然编译器 IDEA 报错,但程序却能正常的执行,那这其中的原因又是为何? ​ 报错原因分析 报错的原因 ...

  4. Error: Cannot find module 'webpack/bin/config-yargs' 报错原因, webpack@4.X踩的坑~

    1 .使用webpack@4.32.2时, 当我通过package.json的script去执行webpack-dev-server时, 报以下错误:  Error: Cannot find modu ...

  5. angularJS中$http.get( ).success( )报错原因及解决方案

    一.问题描述: 电脑安装的angular1.6.7版本,项目中使用了$http.get( ).success( ),控制台报错: $http.get(...).success is not a fun ...

  6. MySQL server has gone away报错原因分析/

    在平时和开发的交流 以及 在论坛回答问题的或称中会发现这个问题被问及的频率非常高. 程序中报错: MySQL server has gone away 是什么意思? 如何避免? 因此,感觉有必要总结一 ...

  7. Java-maven异常-cannot be cast to javax.servlet.Filter 报错, 原因servlet-api.jar冲突

    使用maven开发web应用程序, 启动的时候报错: jar not loaded. See Servlet Spec . Offending class: javax/servlet/Servlet ...

  8. Spring JDBC保存枚举对象含关键字报错原因之一

    报错信息: org.springframework.jdbc.UncategorizedSQLException: PreparedStatementCallback; uncategorized S ...

  9. 黄聪:Wordpress、PHP使用POST数据过大导致MySQL server has gone away报错原因分析

    错误原因: 当POST的数据超过 max_allowed_packet 就会报 MySQL server has gone away 的错误. 1.查看当前Mysql的 max_allowed_pac ...

随机推荐

  1. root用户删除文件提示:Operation not permitted

    root用户删除文件提示:Operation not permitted http://blog.csdn.net/evanbai/article/details/6187578

  2. root用户无法切换到cdh的hive账号上

    在/etc/passwd中看到hive账号是登录的终端是/bin/false,而正常的用户配置的都是/bin/bash,因此在root账号su到hive也是没有用的 hive:x:111:111:Hi ...

  3. Qt之图形(绘制漂亮的圆弧)

    简述 综合前面对二维绘图的介绍,想必我们对一些基本绘图有了深入的了解,下面我们来实现一些漂亮的图形绘制. 简述 圆形 效果 源码 弧形 效果 源码 文本 效果 源码 旋转 效果 源码 圆形 经常地,我 ...

  4. Java数据结构-线性表之单链表LinkedList

    线性表的链式存储结构,也称之为链式表,链表:链表的存储单元能够连续也能够不连续. 链表中的节点包括数据域和指针域.数据域为存储数据元素信息的域,指针域为存储直接后继位置(一般称为指针)的域. 注意一个 ...

  5. poj 2079 Triangle,旋转卡壳求点集的最大三角形

    给出一个点集,求顶点在点集中的最大的三角形面积. 我们知道这三角形的三个点肯定在凸包上,我们求出凸包之后不能枚举,由于题目n比較大,枚举的话要O(n^3)的数量级,所以採用旋转卡壳的做法: 首先枚举三 ...

  6. 树莓派安装node.js

    因为树莓派是arm架构,node.js上并没有提供arm架构的二进制包下载. 试过使用apt包管理安装和直接node.js源代码编译安装(编译了四五个小时...),都没有成功,报非法指令错误,预计还是 ...

  7. Copying

    Aliasing can make program difficult to read because changes made in one place might have unexpected ...

  8. Find and counter

    Find: In a sense, find is the opposite of the [] operator. Instead of taking an index and extracting ...

  9. linux中的swap

    1. 也许你会经常遇到一个经典的swap大小设置问题(比如狗血的面试题). 很多人多会说内存的2倍.. 但是个人认为一般而言 swap 不要设置太大,最好不要超过4G. 2. 进程申请内存不足时,发现 ...

  10. mac终端(terminal)里的快捷键

    Command + K 清屏 Command + T 新建标签 Command +W 关闭当前标签页 Command + S 保存终端输出 Command + D 垂直分隔当前标签页 Command ...