-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdom-element.js
More file actions
47 lines (36 loc) · 1.1 KB
/
dom-element.js
File metadata and controls
47 lines (36 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
var serializeElement = require("./serialize.js")
module.exports = DOMElement
function DOMElement(tagName) {
if (!(this instanceof DOMElement)) {
return new DOMElement(tagName)
}
this.tagName = tagName
this.className = ""
this.dataset = {}
this.childNodes = []
this.parentNode = null
this.style = {}
}
DOMElement.prototype.type = "DOMElement"
DOMElement.prototype.nodeType = 1
DOMElement.prototype.appendChild = function _Element_appendChild(child) {
this.childNodes.push(child)
child.parentNode = this
}
DOMElement.prototype.replaceChild =
function _Element_replaceChild(elem, needle) {
var index = this.childNodes.indexOf(needle)
this.childNodes[index] = elem
elem.parentNode = this
}
DOMElement.prototype.removeChild = function _Element_removeChild(elem) {
var index = this.childNodes.indexOf(elem)
this.childNodes.splice(index, 1)
}
// Un-implemented
DOMElement.prototype.focus = function _Element_focus() {
return void 0
}
DOMElement.prototype.toString = function _Element_toString() {
return serializeElement(this)
}