当前位置:网站首页>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>
边栏推荐
- Leetcode topic [array] - 119 Yang Hui triangle II
- 测试用里hi
- Teach you to learn JS prototype and prototype chain hand in hand, a tutorial that monkeys can understand
- 蓝桥杯 微生物增殖 C语言
- Mind map + source code + Notes + project, ByteDance + JD +360+ Netease interview question sorting
- Computer network: sorting out common network interview questions (I)
- Spark foundation -scala
- 学习探索-无缝轮播图
- About image reading and processing, etc
- 【基础架构】Flink/Flink-CDC的部署和配置(MySQL / ES)
猜你喜欢
ZABBIX proxy server and ZABBIX SNMP monitoring
In depth analysis, Android interview real problem analysis is popular all over the network
Mysql Information Schema 学习(二)--Innodb表
A full set of teaching materials, real questions of Android interview of 7 major manufacturers including Alibaba Kwai pinduoduo
Take a look at how cabloyjs workflow engine implements activiti boundary events
Documents to be used in IC design process
谷粒商城--分布式高级篇P129~P339(完结)
PMP每日一练 | 考试不迷路-7.6
企业精益管理体系介绍
DaGAN论文解读
随机推荐
潇洒郎: AttributeError: partially initialized module ‘cv2‘ has no attribute ‘gapi_wip_gst_GStreamerPipe
ZABBIX proxy server and ZABBIX SNMP monitoring
测试用里hi
Synchronous development of business and application: strategic suggestions for application modernization
手把手教你学会js的原型与原型链,猴子都能看懂的教程
[pytorch] yolov5 train your own data set
在解决了 2961 个用户反馈后,我做出了这样的改变...
系统性详解Redis操作Hash类型数据(带源码分析及测试结果)
史上超级详细,想找工作的你还不看这份资料就晚了
凤凰架构2——访问远程服务
Tensorflow2.0 自定义训练的方式求解函数系数
Teach you to learn JS prototype and prototype chain hand in hand, a tutorial that monkeys can understand
Mysql Information Schema 学习(一)--通用表
How to do smoke test
In 50W, what have I done right?
Phoenix Architecture 2 - accessing remote services
今日直播 | “人玑协同 未来已来”2022弘玑生态伙伴大会蓄势待发
Php+redis realizes the function of canceling orders over time
English topic assignment (25)
Interview assault 63: how to remove duplication in MySQL?