for example i have some HTML elements like below
<p> apple,banana,oranger</p>
and i'd like to use the javascript to make it like
<p>apple</p> <p>banana</p> <p>orange</p>
How may i achieve this?
UPDATE 1:
I am using other methods to do my task due to some reaseon and it looks as like below
var node = document.getElementById('discovereedKeywords');
node.innerHTML = node.innerHTML.replace(/,/g, '<p class="tag-item">');
and in reality those <p>
tags are actually generate by a for loop, but my method only change the first node it found therefore i tried
Consider the html looks like this
<p class="discovereedKeywords"> apple,banana,oranger</p>
<p class="discovereedKeywords"> apple,oranger,oranger</p>
<p class="discovereedKeywords"> kiwi,melon,pinapple</p>
Javascript
for (var i=0; i <data.result.data.length; i++){
var node[i] = document.getElementByClassName('discovereedKeywords');
node[i].innerHTML = node.innerHTML.replace(/,/g, '<p class="tag-item">');
}
}
but this those work, why?
` instead of a span. You likely want to [.replaceWith()](http://api.jquery.com/replacewith/) the `
` you had in the beginning
– mplungjan May 06 '16 at 07:57apple,banana,orange
` – Alexus May 06 '16 at 08:09