当前位置:网站首页>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>
边栏推荐
- GCC [7] - compilation checks the declaration of functions, and link checks the definition bugs of functions
- Interview assault 63: how to remove duplication in MySQL?
- Mysql Information Schema 學習(一)--通用錶
- How to access localhost:8000 by mobile phone
- PMP每日一练 | 考试不迷路-7.6
- Solution of intelligent management platform for suppliers in hardware and electromechanical industry: optimize supply chain management and drive enterprise performance growth
- Excel 中VBA脚本的简单应用
- MySQL information schema learning (II) -- InnoDB table
- 121. 买卖股票的最佳时机
- Mind map + source code + Notes + project, ByteDance + JD +360+ Netease interview question sorting
猜你喜欢

A popular explanation will help you get started

CCNP Part 11 BGP (III) (essence)

利用 clip-path 绘制不规则的图形

思維導圖+源代碼+筆記+項目,字節跳動+京東+360+網易面試題整理

Help improve the professional quality of safety talents | the first stage of personal ability certification and assessment has been successfully completed!

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

今日直播 | “人玑协同 未来已来”2022弘玑生态伙伴大会蓄势待发

系统性详解Redis操作Hash类型数据(带源码分析及测试结果)
![[translation] a GPU approach to particle physics](/img/07/57036c925155cab36678c696e89440.jpg)
[translation] a GPU approach to particle physics

Chic Lang: attributeerror: partially initialized module 'CV2' has no attribute 'GAPI_ wip_ gst_ GStreamerPipe
随机推荐
零基础入门PolarDB-X:搭建高可用系统并联动数据大屏
The slave i/o thread stops because master and slave have equal MySQL serv
A method of removing text blur based on pixel repair
How to do smoke test
Unbalance balance (dynamic programming, DP)
Is not a drawable (color or path): the vector graph downloaded externally cannot be called when it is put into mipmap, and the calling error program crashes
潇洒郎: AttributeError: partially initialized module ‘cv2‘ has no attribute ‘gapi_wip_gst_GStreamerPipe
【翻译】Linkerd在欧洲和北美的采用率超过了Istio,2021年增长118%。
10 schemes to ensure interface data security
Help improve the professional quality of safety talents | the first stage of personal ability certification and assessment has been successfully completed!
学习探索-使用伪元素清除浮动元素造成的高度坍塌
史上超级详细,想找工作的你还不看这份资料就晚了
蓝桥杯 微生物增殖 C语言
Mysql Information Schema 学习(一)--通用表
保证接口数据安全的10种方案
时钟轮在 RPC 中的应用
Elastic search indexes are often deleted [closed] - elastic search indexes gets deleted frequently [closed]
MATLAB中deg2rad和rad2deg函数的使用
Analysis of rainwater connection
swagger2报错Illegal DefaultValue null for parameter type integer