document.getElementById & document.querySelector

https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelectorAll

https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector

https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementById

  1. getElementById 仅支持 id 选择器, 返回 An Element object

  2. querySelector 支持各种选择器, 返回匹配的第一个 An HTMLElement object

https://developer.mozilla.org/en-US/docs/Web/API/Element

https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement

  1. HTMLElement 是父类,base 接口
  2. Element 是子类,实现/继承于 HTMLElement 接口

demo


document.getElementById("demo");
<section id=​"demo">​ ​</section>​
document.querySelector("#demo")
<section id=​"demo">​ ​</section>​
document.querySelectorAll("#demo")
NodeList [section#demo]0: section#demolength: 1__proto__: NodeList
document.getElementById("demo") === document.querySelector("#demo")
true
document.getElementById("demo") == document.querySelector("#demo")
true
typeof document.getElementById("demo")
"object"
typeof document.querySelector("#demo")
"object"

document.getElementById & document.querySelector的更多相关文章

  1. 尝试document.getElementById()失败

    document.getElementById() document.getElementsByTagName() 电脑重启,新建文件后尝试成功

  2. document.getElementsByName和document.getElementById用法

    本文的问题在国外的一个网站得到了答案http://stackoverflow.com/questions/11235409/no-getelementbyid-for-body document.bo ...

  3. document.getElementById和document.querySelector的区别

    zepto中的$(".111")出错,jQuery中$(".111")不出错的原因: zepto用document.querySelector实现,jQuery ...

  4. Id.value与document.getElementById("Id").value的区别

    如果标签Id在Form表单里面的话,直接Id.value就不能用了,而是要用Form.Id.value来取值或设置值 所以最好用document.getElementById("Id&quo ...

  5. document.getElementById()与 $()区别

    document.getElementById()返回的是DOM对象,而$()返回的是jQuery对象 什么是jQuery对象? ---就是通过jQuery包装DOM对象后产生的对象.jQuery对象 ...

  6. jQuery中,$('#main') 与 document.getElementById('main')是什么样的关系-转

    $('#main')[0]和document.getElementById('main')两个一模一样.解释:$('#main'):是一个jquery写法,#main是一个过滤器表示方法,表示查找一个 ...

  7. jquery中的$("#id")与document.getElementById("id")的区别

    以前一直认为jquery中的$("#id")和document.getElementByIdx_x("id")得到的效果是一样的,今天做特效的时候才发现并不是这 ...

  8. 【Asp.Net】document.getElementById 的属性介绍

    document.getElementById("id").style.xxx可以设置指定ID的控件的属性值. 主要支持以下一些属性设置: 盒子标签和属性对照 CSS语法(不区分大 ...

  9. 不绑架输入--document.getElementById("linkage_"+id_type+"_echo").value="";--联动

    <script> function w_linkage(id_type) { var selected = $("#linkage_"+id_type+"_t ...

随机推荐

  1. Main event loop

    https://developer.apple.com/library/archive/documentation/General/Conceptual/Devpedia-CocoaApp/MainE ...

  2. 理想的DevOp流程怎么做?看看Slack的代码部署实践 原创 Michael Deng 高可用架构 今天

    理想的DevOp流程怎么做?看看Slack的代码部署实践 原创 Michael Deng  高可用架构  今天

  3. 长连接 短连接 RST报文

    https://baike.baidu.com/item/短连接 短连接(short connnection)是相对于长连接而言的概念,指的是在数据传送过程中,只在需要发送数据时,才去建立一个连接,数 ...

  4. 网页小实验——用canvas生成精灵动画图片

    实验目标:借助canvas把一张国际象棋棋子图片转换为一组适用于WebGL渲染的精灵动画图片,不借助其他图片处理工具,不引用其他库只使用原生js实现. 初始图片如下: 一.图片分割 将初始图片分割为六 ...

  5. luoguP4999 烦人的数学作业

    写在前面 这两天信息量有点大,需要好好消化一下,呼呼 \(f[i][j]\) 的转移式还是好理解的,但是对于其实际意义课上有点糊 求 \(ans_{1, x}\) 是感觉手动把数拆开看会好理解一点?? ...

  6. php中一种单引号逃逸造成的注入

    demo如下: $post = $_POST; $sql=''; $array['name'] = $post['name']; $array['age'] = 18; $array['addr'] ...

  7. 通过spring statemmachine 自定义构建属于自己的状态机(两种方式)

    spring 的stateMachine 相对于当前的版本,还是比较新颖的,但是对于合适的业务场景,使用起来还是十分的方便的.但是对于官网提供的文档,讲解的是十分的精简,要想更深入的了解其内部架构,只 ...

  8. python模块----pymysql模块 (连接MySQL数据库)

    pymysql模块是专门用来连接mysql数据库的模块,是非标准库模块,需要pip下载 下载 pip install pymysql 查询 import pymysql # 打开数据库连接 db = ...

  9. Spring boot 异步线程池

    package com.loan.msg.config; import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandle ...

  10. HttpURLConnection下载文件流

    package com.loan.modules; import sun.net.www.protocol.file.Handler; import java.io.*; import java.ne ...