简体   繁体   English

JS返回HTML Title作为H1 Headline

[英]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.

相关问题 JS - 连接<h1>和<title>&lt;/div&gt;</title><div id="text_translate"><p> 我要做的就是使标题与 h1 标签完全相同。</p><pre> &lt;title class="blogtitle"&gt;&lt;/title&gt; &lt;h1 class="title"&gt;Updating our staff members&lt;/h1&gt; &lt;script&gt; document.getElementsByClassName("blogtitle")[0].innerHTML = h1; var h1 = document.getElementsByClassName("title") &lt;/script&gt;</pre></div></h1> - JS - Connect <h1> with <title> H1标题设置不正确 - H1 title not setting correcly 如何在 html 和 js 中将变量 Valor 显示到 h1 - How I can show a Variable Valor in to a h1 in html and js 试图更改 h1 标签的内部 html 但 js 抛出错误 - trying to change inner html of h1 tag but js throwing an error 使用 js 迭代 h1 - Iterating h1 using js 两种颜色值,一种用于 h1 标题,一种用于带有 html 和 javascript 的背景 - Two color values one for h1 title and one for the background with html and javascript 画 <svg> 要么 <canvas> 标题之后[html,js] - Draw <svg> or <canvas> after headline [html, js] 更改HTML文本 <h1> 不工作吗? 我是否正确链接了app.js? - Changing text of HTML <h1> not working? Did I link app.js correctly? JS 根据 h1 标签中包含的特定文本切换 HTML 内容 - JS Switch HTML content based on specific text included in h1 tag 如何用node.js查找html元素(比如h1)的具体值 - How to find specific value of html element (such as h1) with node.js
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM