DOM&BOM Operation
Keywords:
Attribute
ftp
xml
The difference between property and attribute
<div id="div1" class="class-div1">
<P id="p1" data-name="p1-data-name">this is p1</P>
<P id="p2">this is p2</P>
</div>
var div1 = document.getElementById('div1')
console.log(div1.className)
div1.className = 'abc'
console.log(div1.className)
var p1 = document.getElementById('p1')
console.log(p1.getAttribute('data-name'))
p1.setAttribute('data-name','xyz')
DOM Structural Operations (DOM Trees, themselves JS Objects)
New node
Get the parent element
Get child elements
Delete node
var div1 = document.getElementById('div1')
var p1 = document.createElement('p')
p1.innerHTML = 'this is p1'
div1.appendChild(p1)
var p2 = document.getElementById('p2')
div1.appendChild(p2)
var div1 = document.getElementById('div1')
var parent = div1.parentElement
var child = div1.childNodes
div1.removeChild(child[0])
console.log(div1.childNodes[0].nodeType)
console.log(div1.childNodes[1].nodeType)
console.log(div1.childNodes[0].nodeName)
console.log(div1.childNodes[1].nodeName)
Answer
What is the basic data structure of DOM
What are the common API s for DOM operations
- Get DOM nodes, as well as properties and attributes of nodes
- Get parent node, get child node
- Add nodes, delete nodes
Attribute and property of DOM nodes are different
- property is just a modification and acquisition of the attributes of a JS object
- Attribute is the modification and acquisition of html tag attributes
Key summary
DOM essence
DOM Node Operation
DOM Structural Operation
BOM Operation (Browser Object Model)
subject
- How to detect the type of browser
- Disassemble the parts of the url
Knowledge points
- navigator Browser
- Screen screen width and height
- location address bar information
- history goes forward and backwards
var ua = navigator.userAgent
var isChrome = ua.indexOf('Chrome')
console.log(isChrome)
console.log(screen.width)
console.log(screen.height)
console.log(location.href)
console.log(location.protocol)
console.log(location.host)
console.log(location.pathname)
console.log(location.search)
console.log(location.hash)
history.back()
history.forward()
How to detect the type of browser
var ua = navigator.userAgent
var isChrome = ua.indexOf('Chrome')
console.log(isChrome)
Disassemble the parts of the url
console.log(location.href)
console.log(location.protocol)
console.log(location.host)
console.log(location.pathname)
console.log(location.search)
console.log(location.hash)
Posted by sunilvadranapu on Thu, 10 Oct 2019 08:39:13 -0700