Thay đổi thẻ H1 thành H2 bằng Javascript [đóng]
Aug 20 2020
Tôi đang tìm cách trong Vanilla JavaScript để thay đổi <h1>thẻ thành <h3>thẻ cho mã HTML này:
<h1 class="price-heading ult-responsive cust-headformat" data-ultimate-target="#price-table-wrap-3686 .cust-headformat" data-responsive-json-new="{"font-size":"","line-height":""}" style="font-family:'Roboto';font-weight:bold;">Basic</h1>
Làm thế nào tôi có thể đạt được điều này?
Trả lời
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/