head.ts 490 B

12345678910111213141516171819
  1. // Helper functions for working with the document head
  2. function createElementInHead(
  3. tag: string,
  4. attributes: [string, string][],
  5. children: string | null
  6. ): void {
  7. const element = document.createElement(tag);
  8. for (const [key, value] of attributes) {
  9. element.setAttribute(key, value);
  10. }
  11. if (children) {
  12. element.appendChild(document.createTextNode(children));
  13. }
  14. document.head.appendChild(element);
  15. }
  16. // @ts-ignore
  17. window.createElementInHead = createElementInHead;