当前位置:网站首页>DOM operation
DOM operation
2022-07-06 19:36:00 【wangatong】
use Id
var a = document.getElementById("id name ")
use class What you get is an array
var a = documen.getElementsByClassName("class name ")
What you get with the tag is an array
var a = document.getElementsByTagName (" Tag name ")
use name What you get is an array
var a = document.getElementsByName( "name name " )
With selector querySelectorAll
document.querySelector("p");
event
onmouseover,onmouseout,onclick,
Modify the style
a.style.
Document: The root node
parentNode: Get parent node
childNodes: Get all children
firstChild: First child node
lastChild: The last child node
<p id="p1" class="p1"> Click on </p>
<div id="div1"></div>
<script>
// let p = document.getElementById('p1') //id
// let p = document.querySelector("#p1")
// let p = document.querySelectorAll("#p1")[0]
// let p = document.getElementsByTagName("p")[0] // label
let p = document.getElementsByClassName('p1')[0] //class class
p.onclick = function(){
console.log(111)
}
p.onmouseover = function(){
console.log(222)
}
p.onmouseout = function(){
console.log(333)
}
let div = document.createElement("p") // Create element node
let content = "dfsfsdfsf"
let txt = document.createTextNode(content) // Create text node
div.appendChild(txt) // Add child nodes
let div1 = document.getElementById("div1")
div1.appendChild(div)
// div1.removeChild(div) // Remove node
let val = div.parentNode.getAttribute("id") // Get parent node , Get attribute value
// alert(val)
div.parentNode.setAttribute("name","12") // Set properties
// prompt("What's your name?", "Default")
// var re = confirm(" Delete ?");
// if(re == false){
// console.log('false')
// }else{
// console.log('true')
// }
console.log(navigator.language)
console.log(document.title)
console.log(document.head)
</script>
边栏推荐
- spark基础-scala
- 潇洒郎: AttributeError: partially initialized module ‘cv2‘ has no attribute ‘gapi_wip_gst_GStreamerPipe
- zabbix 代理服务器 与 zabbix-snmp 监控
- Hudi vs Delta vs Iceberg
- English topic assignment (25)
- 零基础入门PolarDB-X:搭建高可用系统并联动数据大屏
- 主从搭建报错:The slave I/O thread stops because master and slave have equal MySQL serv
- Translation D28 (with AC code POJ 26:the nearest number)
- 反射及在运用过程中出现的IllegalAccessException异常
- C # use Marshall to manually create unmanaged memory in the heap and use
猜你喜欢

企业精益管理体系介绍

Live broadcast today | the 2022 Hongji ecological partnership conference of "Renji collaboration has come" is ready to go

CPU负载很低,loadavg很高处理方法

Characteristic colleges and universities, jointly build Netease Industrial College

spark基础-scala

Php+redis realizes the function of canceling orders over time

Chic Lang: attributeerror: partially initialized module 'CV2' has no attribute 'GAPI_ wip_ gst_ GStreamerPipe

Detailed idea and code implementation of infix expression to suffix expression
In depth analysis, Android interview real problem analysis is popular all over the network

Leetcode 30. 串联所有单词的子串
随机推荐
PMP practice once a day | don't get lost in the exam -7.6
Learning and Exploration - function anti shake
Don't miss this underestimated movie because of controversy!
Swagger2 reports an error illegal DefaultValue null for parameter type integer
理解 YOLOV1 第二篇 预测阶段 非极大值抑制(NMS)
中缀表达式转后缀表达式详细思路及代码实现
ZABBIX proxy server and ZABBIX SNMP monitoring
冒烟测试怎么做
Looting iii[post sequence traversal and backtracking + dynamic planning]
手把手教你学会js的原型与原型链,猴子都能看懂的教程
Lick the dog until the last one has nothing (simple DP)
【翻译】数字内幕。KubeCon + CloudNativeCon在2022年欧洲的选择过程
Php+redis realizes the function of canceling orders over time
Tensorflow2.0 自定义训练的方式求解函数系数
GCC【7】- 编译检查的是函数的声明,链接检查的是函数的定义bug
Druid database connection pool details
【翻译】供应链安全项目in-toto移至CNCF孵化器
swagger2报错Illegal DefaultValue null for parameter type integer
Hudi vs Delta vs Iceberg
Mathematical knowledge -- code implementation of Gaussian elimination (elementary line transformation to solve equations)