Below is a code snippet
var pTags=document.getElementsByTagName('p');
for(i=0;i<pTags.length;i++)
{
var p=pTags[i], div=document.createElement('div');
div.innerHTML='P tag replaced with a div tag';
p.parentNode.replaceChild(div, p);
}
It should replace all P
tags with Div
but it's not replacing all but some of them. The red
ones (fiddle) are not replacing.
I don't need this but I want to know what is I'm doing wrong here ? So, my question is why not it's working in this way. Hope someone can tell me the fact.
Thanks for your effort!