I'm having a hard time figuring out how to run a method on certain elements/nodetypes but not others.
For instance here's some HTML:
<div id="parent">
<div class="subparent">Changing Text
<div class="no-change">Changing Text</div>
</div>
<div class="subparent">Changing Text</div>
<div class="child">Changing Text
<div class="no-change">Changing Text</div>
</div>
<div class="subparent">Changing Text</div>
</div>
My method is something like this:
jQuery.fn.changingtext = function(expr) {
return this.each(function() {
this.innerHTML = this.innerHTML
.replace(/Changing Text/ig, "Edited!")
});
};
Now I want to change the text of everything except what's in div.no-change. The end result should be something like this:
<div id="parent">
<div class="subparent">Edited!
<div class="no-change">Changing Text</div>
</div>
<div class="subparent">Edited!</div>
<div class="child">Edited!
<div class="no-change">Changing Text</div>
</div>
<div class="subparent">Edited!</div>
</div>
I don't know of any way to select a parent without also running the method on its child. Any help would be appreciated. Thanks!
Edit: Here is using Paulo's code and not working: http://jsbin.com/usaxa
Edit@Jeff Meatball Yang: Hi, using your inplace replacement it outputs as text rather than html: http://jsbin.com/idina
I also wasn't able to get the other methods working: http://jsbin.com/aguca
Could you provide an example please?
Thanks!