javascript - How to replace html tags using jquery -
i want change div , span tags tr td using java script. java script replace function replace first occurrence , leaves rest was.
<div style="width:100%"> <div style="border-bottom:1px solid #dddddd; padding:10px 0px; height:100%; overflow:hidden;"> <span style="width:420px; display:block; float:left; border-bottom:1px thin #333333;background:#f2f2f2"> custom stirrups : category - adult ,size-one size fits </span> <span style="width:220px; display:block; float:left; border-bottom:1px thin #333333;background:#f2f2f2"> no </span> <span style="width:140px; display:block; float:left; border-bottom:1px thin #333333;background:#f2f2f2"> 1 </span><br /> </div> <div style="border-bottom:1px solid #dddddd; padding:10px 0px; height:100%; overflow:hidden;"> <span style="width:420px; display:block; float:left; border-bottom:1px thin #333333;background:#f2f2f2"> flat visor fitted : fitted sizes - 7 1/8 </span> <span style="width:220px; display:block; float:left; border-bottom:1px thin #333333;background:#f2f2f2"> no </span> <span style="width:140px; display:block; float:left; border-bottom:1px thin #333333;background:#f2f2f2"> 1 </span> <br /> </div> </div>
i want similar this
<table width="100%"> <tbody> <tr> <td width="471" style="background:#f2f2f2">cap : fitted sizes - 6 5/8 </td> <td width="240" style="background:#f2f2f2">yes</td> <td width="145" style="background:#f2f2f2">1</td> </tr> <tr> <td width="471" style="background:#f2f2f2">grey dri-fit undershirt : size - xxl </td> <td width="240" style="background:#f2f2f2">yes</td> <td width="145" style="background:#f2f2f2">1</td> </tr> </tbody> </table>
this script trying...please let me know m wrong
var data = $('#dvdata').html(); data = data.replace('/<div style="width:100%">/g', '<table width="100%"><tbody><tr>'); data = data.replace('/</div>/g', '</tbody></table></tr>');
thanks in advance..
see http://www.w3schools.com/jsref/jsref_replace.asp it's global replacement:
var str="mr blue has blue house , blue car"; var n=str.replace(/blue/g,"red");
other examples provided there well.
Comments
Post a Comment