EN
JavaScript - access head element
8
points
In this short article, we would like to show how to get <head> element reference in JavaScript.
Quick solution:
var headElement = document.head;
Practical example
// ONLINE-RUNNER:browser;
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>Page title</title>
</head>
<body>
<script>
var headElement = document.head; // head element reference
console.log(headElement.outerHTML);
</script>
</body>
</html>