Created
September 9, 2016 12:37
-
-
Save racinmat/4a207a12e8ea1851957de7f0cf163687 to your computer and use it in GitHub Desktop.
appending html with javascript
This file contains 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 lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Title</title> | |
</head> | |
<body> | |
<h2>seznam</h2> | |
<ul> | |
<li>položka</li> | |
<li>položka 2</li> | |
</ul> | |
<script type="application/javascript"> | |
window.onload = function () { | |
console.log('onload event triggered'); | |
//using document write after onload creates new html document and wipes out averything rendered before it | |
// document.write(' <h2>další seznam</h2> ' + | |
// '<ul> ' + | |
// '<li>jiná položka</li> ' + | |
// '<li>jiná položka 2</li> ' + | |
// '</ul>'); | |
// console.log('html added with document.write'); | |
var div = document.createElement("div"); | |
div.innerHTML = ' <h2>další seznam</h2> ' + | |
'<ul> ' + | |
'<li>jiná položka</li> ' + | |
'<li>jiná položka 2</li> ' + | |
'</ul>'; | |
document.body.appendChild(div); | |
console.log('html added with createElement'); | |
}; | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment