Replace using jquery even on html tags -


sounds simple, spent @ least 6 hours no luck.

for example, have following code

<div data-width="123">    <p>hi 123</p>  <img src="123.jpg" /> </div> 

and need transform every 123 999

<div data-width="999">    <p>hi 999</p>  <img src="999.jpg" /> </div> 

i've tried using several "replacing" methods, nothing works. need replace 999 every 123.

thanks guys!

assume wrap using element

<div class='test'>     <div data-width="123">        <p>hi 123</p>      <img src="123.jpg" />    </div>      </div> 

you can this

$('.test').html($('.test').html().replace(/123/g, '999')); 

you take out elements inside element string , string replace , put modified string element.

see demo below

http://jsfiddle.net/petrabarus/ph5qz/

or can this

$('body').html($('body').html().replace(/123/g, '999')); 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -