0

I wanted this code to work without needing to use jquery to get the header tag:

<head>
   <script type="text/javascript" src="js/lib/jquery-1.11.1.min.js" ></script>
   <script> 
     $(function(){ $("head").load("header.html") });
   </script>
</head>
pico
  • 1,660
  • 4
  • 22
  • 52
  • Don't confuse the header tag (`
    `) with the head tag (`)` they are quite different.
    – Quentin Feb 04 '20 at 16:00
  • **Danger**: jQuery 1.x is beyond end of life and has known security issues. Use a supported version of jQuery. – Quentin Feb 04 '20 at 16:01
  • I dont know why you should do that but... fetch("urlToGetData").then((data)=>{return data.text}).then(function(textBodyResponse) { document.querySelector('#div').innerHTML = textBodyResponse; }); asume head is not header or something like that Regards – Augusto Feb 04 '20 at 16:04
  • 1
    For getting the head use document.getElementsByTagName("head")[0]; – DenverCoder1 Feb 04 '20 at 16:05
  • For equivalent to .load(): https://stackoverflow.com/questions/17901116/i-need-the-equivalent-of-load-to-js – DenverCoder1 Feb 04 '20 at 16:06

1 Answers1

2

How's this?

document.getElementsByTagName('head')[0].innerHTML

Or if you are in fact looking for header tags:

document.getElementsByTagName('header')[0].innerHTML
Greg
  • 1,845
  • 2
  • 16
  • 26