jquery - Replace Text but not inside url -


i have following structure:

<div class='xx'>   awesome!! <a href="http://www.his-stuff.com">yodel</a> </div>  <div class='xx'>    can't touch </div> 

now want replace occurrances of "is", no matter if standing alone or not. made way:

$('.xx').each(function() {    $(this).html($(this).html().replace("is","was")); }); 

i want following results:

that awesome -> awesome

can't touch -> can't touch thwas

this works, url containing "is" modified

www.hwas-stuff.com

i not want url replaced others

info: cannot use text() instead of html() because "real" code bit more complex (inserts images instead of text)

try this:

$('.xx').contents().filter(function() {     return this.nodetype == node.text_node && this.nodevalue.trim() != ''; }).each(function() {     this.nodevalue = this.nodevalue.replace('is','was'); }); 

working demo

from question asked on stack overflow: https://stackoverflow.com/a/11167387/1420186


Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -