[英]JS Return HTML Title as H1 Headline
first of all: I'm not a coder!首先:我不是程序员!
I want to inject a dynamic h1 based on page title on a webpage.我想根据网页上的页面标题注入动态 h1。
Example: <title>Garden</title>
示例:
<title>Garden</title>
Now I need this as H1 class - I want to include this H1 after a given div class <div class="teaser"></div>
现在我需要这个作为 H1 class - 我想在给定的 div class
<div class="teaser"></div>
之后包含这个 H1
It is may totally simple and I already read some stuff but i don't get it…它可能非常简单,我已经读过一些东西,但我不明白……
Fairly trivial相当琐碎
window.addEventListener('DOMContentLoaded', function() { const h1 = document.createElement('h1') h1.innerHTML = document.title; document.querySelector(".teaser").insertAdjacentElement("afterend", h1) })
<!doctype html> <html> <head> <meta charset="utf-8"> <title>Garden</title> </head> <body> <div class="teaser">Teaser</div> </body> </html>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.