Измените тег H1 на H2 с помощью Javascript [закрыто]

Aug 20 2020

Я ищу способ в Vanilla JavaScript изменить <h1>тег на <h3>тег для этого HTML-кода:

<h1 class="price-heading ult-responsive cust-headformat" data-ultimate-target="#price-table-wrap-3686 .cust-headformat" data-responsive-json-new="{&quot;font-size&quot;:&quot;&quot;,&quot;line-height&quot;:&quot;&quot;}" style="font-family:'Roboto';font-weight:bold;">Basic</h1>

Как я могу этого добиться?

Ответы

1 Dalibor Aug 20 2020 at 15:50
var el = document.getElementsByTagName('h1')[0];
var dummy = document.createElement('h2');
dummy.innerHTML = el.innerHTML;
el.parentNode.replaceChild(dummy, el);

https://jsfiddle.net/Lzg47mek/