简体   繁体   中英

How can I write a script which help me to add H1 tag in between Div tag in html?

I am working on Squarespace website. I am trying to add H1 tag automatically via script in Div tag. Below is the div tag in which I have text. I want to asign H1 tag to this text via script or any other method.

<div class="image-slide-title">
St. Stephens
</div>

The squarespace doesn't allow me to add H1 tag manually via coding. I can't use CSS code and when I use CSS code it changes the class and mess the area.

在此处输入图像描述

You could try to insert it in the DOM, like this:

const myDiv = document.getElementsByClassName('image-slide-title')[0];

let title = document.createElement('h1');
title.innerHTML = 'whatever you would like it to be';

myDiv.appendChild(title);

If in the div there is only a text:

$('.image-slide-title').html("<h1>" + $('.image-slide-title').text() + "</h1>");

Try the following code snippet,

 var container = document.querySelector('.image-slide-title'); var title = '<h1>'+container.innerHTML+'</h1>'; container.innerHTML = title;
 <div class="image-slide-title"> St. Stephens </div>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM