I need a simple extension that deletes all divs (with any ID or class). Extension should be running in WP text editor, so I'm using
textEditor.value = textEditor.value
I guess it should use .replaceAll, but I'm not sure how to word expression to delete all divs and ignore their ID and class. Both ID and class should be deleted also.
Example:
<div id="example1" class="example2">Text</div>
Should be just:
<p>Text<p>
This will search for all div tags in the current DOM. And replace it with the span tag.
var divs = document.querySelectorAll("div");
var l = divs.length
for(var i = 0; i < l; i++){
var text = divs[i].innerText;
var p = document.createElement("p");
p.innerText = text;
divs[i].replaceWith(p);
}
var elem = document.getElementById("myDiv");
var html = elem.innerHTML;
var parent = elem.parentNode;
var textEl = document.createElement('p')
textEl.innerHTML = html
parent.appendChild(textEl)