Javascript: Replace all P tags with Div (without any library)
<p>Below is a code snippet</p>

<pre><code>var pTags=document.getElementsByTagName('p');
for(i=0;i&lt;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);
}
</code></pre>

<p>It should replace all <code>P</code> tags with <code>Div</code> but it's not replacing all but some of them. The <code>red</code> ones (<a href="http://jsfiddle.net/eZNqn/" rel="nofollow">fiddle</a>) are not replacing.</p>

<p>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.</p>

<p>Thanks for your effort!</p>
