Created
July 14, 2018 21:36
-
-
Save kmoskwiak/873db06cb83973bb9cb2b4cd893dd850 to your computer and use it in GitHub Desktop.
Create HTML element
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyCustomElement { | |
constructor(id) { | |
let html = this.getHtml(id); | |
let temporaryContainer = document.createElement('div'); | |
temporaryContainer.innerHTML = html.trim(); | |
this.element = temporaryContainer.firstChild; | |
} | |
getElement() { | |
return this.element; | |
} | |
getHtml(id) { | |
return ` | |
<div id="${id}"> | |
<h1>Hello!</h1> | |
</div> | |
`; | |
} | |
} | |
const container = document.getElementById('container'); | |
const myElement = new MyCustomElement('asd-123'); | |
container.appendChild(myElement.getElement()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title></title> | |
<meta name="author" content=""> | |
<meta name="description" content=""> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
</head> | |
<body> | |
<div id="container"></div> | |
<script src="app.js"></script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment