May want to look at Ariel Flesler's Translator:
http://flesler.blogspot.com/2008/05/textnode-translator-for-javascript.html
I used it to write a simple incrementor for numerals within a selected
set.
jQuery.fn.incr = function(amount, fn) {
amount = typeof amount == 'undefined' ? 1 : Number(amount);
fn = fn || function(a){return amount + Number(a);}
var tr = new Translator(function( text ){
return text.replace(/(-?\d+)/g, fn ); // <-- find numerals
});
return this.each(function() {
tr.traverse(this);
})
}
--> $('.votes').incr(1)
--> $('.votes').incr(-2)
Also useful:
jQuery.fn.incrTo = function(amount, fn) {
return $(this).incr(amount, fn || amount);
}
--> $('.votes').incrTo(0);
This will increment all numerals (including negative ones) with in a
wrapper set, including child elements.
On Aug 24, 1:20 pm, "Tom B." <[EMAIL PROTECTED]> wrote:
> Does anyone have code for atextnode selector? I saw this
> post:http://groups.google.com/group/jquery-en/browse_thread/thread/2dda271...
>
> but the function textNodes didn't seem to work with the current
> version ofjQuery. I'm a bit new tojQuery, but I ultimately want to
> do a regex find and replace on all of thetextnodesin a tree (the
> function needs toselectchildren, grandchildren, etc), so any tips on
> the best way to do that would be greatly appreciated.
>
> Many thanks,
> Tom