当前位置:网站首页>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>
边栏推荐
- 350. 两个数组的交集 II
- Synchronous development of business and application: strategic suggestions for application modernization
- Characteristic colleges and universities, jointly build Netease Industrial College
- 凤凰架构3——事务处理
- Tensorflow2.0 自定义训练的方式求解函数系数
- JDBC详解
- swagger2报错Illegal DefaultValue null for parameter type integer
- Simple application of VBA script in Excel
- Chic Lang: attributeerror: partially initialized module 'CV2' has no attribute 'GAPI_ wip_ gst_ GStreamerPipe
- Php+redis realizes the function of canceling orders over time
猜你喜欢
Interpretation of Dagan paper
【翻译】云原生观察能力微调查。普罗米修斯引领潮流,但要了解系统的健康状况仍有障碍...
10 schemes to ensure interface data security
Actf 2022 came to a successful conclusion, and 0ops team won the second consecutive championship!!
Solution of commercial supply chain management platform for packaging industry: layout smart supply system and digitally integrate the supply chain of packaging industry
在解决了 2961 个用户反馈后,我做出了这样的改变...
Phoenix Architecture 3 - transaction processing
MySQL information schema learning (II) -- InnoDB table
学习探索-使用伪元素清除浮动元素造成的高度坍塌
C language daily practice - day 22: Zero foundation learning dynamic planning
随机推荐
Simple understanding of MySQL database
How can my Haskell program or library find its version number- How can my Haskell program or library find its version number?
三面蚂蚁金服成功拿到offer,Android开发社招面试经验
Dark horse -- redis
Swiftui game source code Encyclopedia of Snake game based on geometryreader and preference
Unbalance balance (dynamic programming, DP)
Cereals Mall - Distributed Advanced p129~p339 (end)
350. 两个数组的交集 II
Mathematical knowledge -- code implementation of Gaussian elimination (elementary line transformation to solve equations)
Mysql Information Schema 学习(一)--通用表
学习探索-使用伪元素清除浮动元素造成的高度坍塌
终于可以一行代码也不用改了!ShardingSphere 原生驱动问世
力扣101题:对称二叉树
[translation] linkerd's adoption rate in Europe and North America exceeded istio, with an increase of 118% in 2021.
CCNP Part 11 BGP (III) (essence)
Leetcode 30. 串联所有单词的子串
USB host driver - UVC swap
Solution of commercial supply chain management platform for packaging industry: layout smart supply system and digitally integrate the supply chain of packaging industry
The second day of rhcsa study
English topic assignment (25)