-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsmall.js
41 lines (25 loc) · 1.19 KB
/
small.js
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
'use strict'
// 참고
// https://stackoverflow.com/questions/3103962/converting-html-string-into-dom-elements/3104237
// https://stackoverflow.com/questions/38335920/why-is-domparser-not-preserving-inline-styles-of-parsed-dom
let domMaker = {
}
domMaker.fromString = function(xmlString){
let htmlelement = new DOMParser().parseFromString(xmlString, 'text/xml').firstChild;
return htmlelement;
}
domMaker.fromTag = function(tagName){
let xmlString = `<${tagName} xmlsns=\"http://www.w3.org/1999/xhtml\"></${tagName}>`;
let htmlelement = new DOMParser().parseFromString(xmlString, 'text/xml').firstChild;
return htmlelement;
}
domMaker.fromTagId = function(tagName, idName){
let xmlString = `<${tagName} xmlsns=\"http://www.w3.org/1999/xhtml\" id=\'${idName}\'></${tagName}>`;
let htmlelement = new DOMParser().parseFromString(xmlString, 'text/xml').firstChild;
return htmlelement;
}
domMaker.fromTagIdClass = function(tagName, idName, className){
let xmlString = `<${tagName} xmlsns=\"http://www.w3.org/1999/xhtml\" id=\'${idName}\'></${tagName}>`;
let htmlelement = new DOMParser().parseFromString(xmlString, 'text/xml').firstChild;
return htmlelement;
}