当前位置:网站首页>Web API - get elements and event basis
Web API - get elements and event basis
2022-07-16 06:08:00 【mintsolace】
1. How to get page elements
DOM In actual development, it is mainly used to operate elements
There are several ways to get the elements in the page :
(1) according to ID obtain
(2) Get... According to the tag name
(3) according to HTML5 New method to get
(4) Special element acquisition
2. according to ID obtain
Use getElementById() Method can get the ID The element object of
element It's a Element object , If there is a specific in the current document ID If the element does not exist, it returns null
id Is a case sensitive string , Represents the unique name of the element to be found ID
// What is returned is the collection of obtained element objects , Store... As a pseudo array
document.getElementsByTagName('li');// You can get some tags in this element
var nav = document.getElementById('nav');//ID only one , What we got was this nav Elements
getElementsByClassName Get a collection of certain elements according to the class name
document.getElementsByClassName('box');
querySelector Returns the first element object of the specified selector
var firstBox = document.querySelector('.box');
querySelectorAll() Returns a collection of all element objects of the specified selector
var allBox = document.querySelectorAll('.box');
3. Get special elements (body, html)
var bodyEle = document.body;// obtain body Elements
var htmlEle = document.documentElement;// obtain html Elements
The basis of the event : Trigger response mechanism .
Javascript It gives us the ability to create dynamic pages , Events can be Javascript Detected behavior .
Every element in a web page can produce something that can trigger Javascript Events , For example, an event can be generated when a user clicks a button , And then do something .
Three elements of the event : That is, the event consists of three parts : Event source , Event type , Event handler .
Event source : The event is triggered by , Button .
Event type : How to trigger , What event : Mouse click or pass or press ?
Event handler : Through a function assignment
边栏推荐
- ES6 -- object
- Open source internship | compiler sig internship task is officially released. Welcome to apply!
- DVA data flow
- Use Base64 to encode pictures and byte[]
- CGRect、CGPoint等不能添加到数组中问题
- 计算LocalDate之间的天数差,方便快捷
- 将字符串转为时间晚了5天,避坑指南
- ES6 -- Deconstruction assignment (key)
- Unity experiment - simulating the motion of stars in the solar system
- ES6 -- class
猜你喜欢

WKWebView之离线加载以及遇到的问题

JS downloads files according to binary data

【Missing Semester L5】命令行环境Command-line Environment(进程控制、tmux、别名、配置、SSH)

摩斯隐私计算一体机全项通过深圳国金测评中心83项测评

36.js-- prototype chain 2-- (mainly written test questions)
利用Spark预测回头客实验报告

Notes 2 of network communication security

Garbage collection mechanism

Nftscan Developer Platform launches Multi Chain NFT data pro API service

【MIT Missing Semester 2】Shell Tools
随机推荐
Calculer la différence de jours entre les dates locales est pratique et rapide
摩斯隐私计算一体机全项通过深圳国金测评中心83项测评
41.js -- closure
Object member detection
读SDWebImage源码笔记
40.js -- the same name identifier promotion problem
欧拉Talk | 开发者社区体验坦白局7月14日19:30约起
The technology once selected in the top meeting completed the commercialization of ant chain and launched the copyright AI computing engine
Convert list data to tree data
编译原理-语法分析器设计
微信小程序开发二三事
Use tkmapper to add, delete, modify and query
利用RAC实现验证码发送逻辑
JS scope chain
网络通信安全部分笔记二
YYModel内部实现原理
ES6 -- object
谷歌浏览器无法打开localhost:3000,打开localhost就跳转测试地址问题
Graphic and image programming practice course report
Analyse, capture et simulation du Protocole ARP par sniffer pro