1

I could help, I need a code in jQuery to do the following:

A code each time it finds "Texto 0" in any part of the body. When is "Texto 0" replace style1 by style2 (or remove style1 and add style2)

My code is this. The "..." represent other codes in between.

<div span="menu> <span> Texto 0 </ span> </ div>
....
....
...
<span class="style1"> Hello </ span>
  • maybe that's what you're looking for? http://stackoverflow.com/questions/2145988/string-replace-in-jquery – yacon Mar 07 '13 at 15:53

2 Answers2

1
$('span:contains("Texto 0")').each(function() {
    if($(this).hasClass('style1'))
        $(this).removeClass('style1').addClass('style2');
});

JSFiddle example.

James Donnelly
  • 126,410
  • 34
  • 208
  • 218
0
   $('span').each(function(index) {
     if($(this).val().indexOf("Text 0") !== -1) {
       $(this).removeClass('style1')
       $(this).addClass('style2')
     }
   })
bonyiii
  • 2,833
  • 29
  • 25
  • Thanks for your answers, but I think I did not explain well. Esque I need this code to a forum. I need code in jQuery using 1.7.2. The "...." other codes represent images, paragraphs, tables, etc.. [JSFIDDLE][1] When the "Texto 0" style1 by style2 change. If you are not the "Texto 0", the default style is style1. I mean, if it is not "Texto 0", the function would not apply [1]: http://jsfiddle.net/Kf7pZ/2/ – Xpress Gunz Bk Mar 07 '13 at 16:57