Reputation: 1
I am trying to involve an element that is within a navigation with a SPAN. How do I do that? I already got the element, but now I need to wrap it with SPAN.
let nodes = document.querySelector('nav.bs__pagination').childNodes;
const newDiv = document.createElement("div");
nodes.forEach(function(item) {
if(item.nodeType == 3) {
item.insertBefore(newDiv, item);
}
});
I tried insertBefore but without success, I need to add both before and after in the case: and
Upvotes: 0
Views: 54
Reputation: 92
You could make a span element and then append the element inside of the span
const span = document.createElement("span") // Creates a span element
span.append(elementToAppend) // Inserts an element into the span
document.querySelector("nav").append(span) // Adds the span into a nav tag
Upvotes: 1