'from "p" to a "list"
Good day!
I am using WordPress and this plugin outputs products in one p tag and separates them with a semicolon as in the image.
I was wondering if it is possible somehow to take the values of that p tag and output them in a list? One under the other?
Or perhaps this is a JavaScript question? Or maybe even I should fiddle with the WordPress plugin itself?
I will appreciate any help or hints!
Thanks
Solution 1:[1]
You could use a simple script like this to extract the text content of p, separate each entry after each semicolon and map with p tags:
const parent = document.querySelector("dd.variation-bundledProducts")
const elems = document.querySelector("dd.variation-bundledProducts p").textContent.split(";").map(el => `<p>${el}</p>`).join("");
parent.innerHTML = elems
<dd class="variation-bundledProducts">
<p>
element1; element2; element3; element4
</p>
</dd>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Cesare Polonara |
