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. 获取控制台的错误信息 onerror

    js 获取控制台的错误信息 https://www.bbsmax.com/A/Vx5ML2NmJN/ <!DOCTYPE html> <html lang="en" ...

  2. 洛谷P3501

    Description 对于一个 \(0/1\) 串,如果取反后再将整个串反过来和原串一样,就称作「反对称」字符串 给出一个长度为 \(n\) 的 \(0/1\) 串,求它有多少个反对称子串 Solu ...

  3. ResponseEntity和@ResponseBody以及@ResponseStatus区别

    看的迷迷糊糊的 https://www.jdon.com/springboot/responseentity.html

  4. EasyConnect连接成功后,虚拟ip地位未分配

    文章目录 #问题描述: 今天公司做项目,连接上EasyConnect以后,显示连接成功,但是虚拟ip地址未分配,导致无法远程连接数据库,以及svn无法更新项目. #解决办法: 百度网上各种解决办法,没 ...

  5. isEmpty isBlank 区别

    Sring test="  "; 这个 isblank 返回 true 但是 isEmpty 返回 false   所以: 一般用 isBlank 就可以了 ,是逐个字符检查 pu ...

  6. CCF-命令行选项(模拟)

    命令行选项   问题描述 请你写一个命令行分析程序,用以分析给定的命令行里包含哪些选项.每个命令行由若干个字符串组成,它们之间恰好由一个空格分隔.这些字符串中的第一个为该命令行工具的名字,由小写字母组 ...

  7. Java编程工具IDEA的使用

    IDEA psvm + Enter 快速构建main方法 sout + Enter 快速打印与句 Ctrl+Shift + Enter,语句完成 Ctrl+F12,可以显示当前文件的结构 Ctrl + ...

  8. cassandra权威指南读书笔记--cassandra概述

    cassandra是一个开源的.分布式.去中心化.弹性可扩展.高可用.容错.可调一致性.面向行数据库,分布式设计基于Amazon Dynamo,数据模型基于Google BigTable.cassan ...

  9. linux虚拟摄像头vivid配置

    总述    最近在看摄像头驱动,需要配置虚拟摄像头的驱动,但是教程里面是linux2.6内核的,实际电脑的是Ubuntu16,内核是linux4.15版本,从2.6到4.15内核好多文件发生了变化,所 ...

  10. hdu5459 Jesus Is Here

    Problem Description I've sent Fang Fang around 201314 text messages in almost 5 years. Why can't she ...