Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to replace html tags using jquery
    text
    copied!<p>I want to change div and span tags to tr td using java script. But java script replace function only replace the first occurrence and leaves rest as it was.</p> <pre><code>&lt;div style="width:100%"&gt; &lt;div style="border-bottom:1px solid #DDDDDD; padding:10px 0px; height:100%; overflow:hidden;"&gt; &lt;span style="width:420px; display:block; float:left; border-bottom:1px thin #333333;background:#F2F2F2"&gt; Custom Stirrups : Category - Adult ,Size-One size fits most &lt;/span&gt; &lt;span style="width:220px; display:block; float:left; border-bottom:1px thin #333333;background:#F2F2F2"&gt; NO &lt;/span&gt; &lt;span style="width:140px; display:block; float:left; border-bottom:1px thin #333333;background:#F2F2F2"&gt; 1 &lt;/span&gt;&lt;br /&gt; &lt;/div&gt; &lt;div style="border-bottom:1px solid #DDDDDD; padding:10px 0px; height:100%; overflow:hidden;"&gt; &lt;span style="width:420px; display:block; float:left; border-bottom:1px thin #333333;background:#F2F2F2"&gt; Flat Visor Fitted : Fitted Sizes - 7 1/8 &lt;/span&gt; &lt;span style="width:220px; display:block; float:left; border-bottom:1px thin #333333;background:#F2F2F2"&gt; NO &lt;/span&gt; &lt;span style="width:140px; display:block; float:left; border-bottom:1px thin #333333;background:#F2F2F2"&gt; 1 &lt;/span&gt; &lt;br /&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>I want something similar to this</p> <pre><code>&lt;table width="100%"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td width="471" style="background:#F2F2F2"&gt;Cap : Fitted Sizes - 6 5/8 &lt;/td&gt; &lt;td width="240" style="background:#F2F2F2"&gt;YES&lt;/td&gt; &lt;td width="145" style="background:#F2F2F2"&gt;1&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td width="471" style="background:#F2F2F2"&gt;Grey Dri-fit Undershirt : Size - XXL &lt;/td&gt; &lt;td width="240" style="background:#F2F2F2"&gt;YES&lt;/td&gt; &lt;td width="145" style="background:#F2F2F2"&gt;1&lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt; </code></pre> <p>this is my script which i was trying...please let me know where i m wrong</p> <pre><code>var data = $('#dvData').html(); data = data.replace('/&lt;div style="width:100%"&gt;/g', '&lt;table width="100%"&gt;&lt;tbody&gt;&lt;tr&gt;'); data = data.replace('/&lt;/div&gt;/g', '&lt;/tbody&gt;&lt;/table&gt;&lt;/tr&gt;'); </code></pre> <p>Thanks in advance..</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload