You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在<label>标签中以文本元素形式渲染<body>标签?

How to Render </body> as Plain Text Inside a <label> Tag

Got it, let's sort this out for you! The problem you're running into is that browsers automatically parse </body> as actual HTML syntax instead of displaying it as regular text. To make it show up correctly inside your <label> tag, you need to escape those special HTML characters so the browser treats them as text, not code.

Static HTML Solution

The simplest fix for static HTML is to replace the angle brackets with their corresponding HTML character entities:

  • Replace < with &lt;
  • Replace > with &gt;

Here's your updated code with the escaped </body> tag:

<label for="message-text" class="col-form-label">
  <strong>Copy and paste this code in Google Tag Manager as custom html or paste this code before &lt;/body&gt; tag on your website page(s).</strong>
</label>

When rendered, this will display exactly as you want: Copy and paste this code in Google Tag Manager as custom html or paste this code before tag on your website page(s).

Dynamic Content Solution (JavaScript)

If you're generating this label content dynamically with JavaScript, avoid using innerHTML (which parses HTML) and use textContent instead. This property automatically escapes special characters, so you can write </body> directly without worrying about entity codes:

// Get your label element
const messageLabel = document.querySelector('label[for="message-text"]');

// Set the text content directly
messageLabel.textContent = 'Copy and paste this code in Google Tag Manager as custom html or paste this code before </body> tag on your website page(s).';

// If you need to keep the <strong> formatting, you can create the strong element separately:
const strongText = document.createElement('strong');
strongText.textContent = 'Copy and paste this code in Google Tag Manager as custom html or paste this code before </body> tag on your website page(s).';
messageLabel.appendChild(strongText);

That's all there is to it! Either escaping the entities in static HTML or using textContent for dynamic content will make </body> show up as plain text in your label.

内容的提问来源于stack exchange,提问作者Sireini

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 10:25:55