I am trying to search and replace all instances of the same word without being case sensitive using .contains (), but it seems to not work and is case sensitive. Here is the code for what I have now:
<p>some text</p>
<p>Some Text</p>
<p>Some TEXT</p>
jQuery.expr[':'].Contains = function(a, i, m) {
return jQuery(a).text().toUpperCase()
.indexOf(m[3].toUpperCase()) >= 0;
};
jQuery.expr[':'].contains = function(a, i, m) {
return jQuery(a).text().toUpperCase()
.indexOf(m[3].toUpperCase()) >= 0;
};
$('p').filter(":contains('some text')").each(function(){
$(this).text($(this).text().replace("some text", "replace with new text"));
});
This only changes the first text due to the same case, you can see an example on js fiddle here
http://jsfiddle.net/ka82V/
Kevin source
share