[jQuery] Re: How to select all text in a div except ul

2009-05-11 Thread nick
Awesome, thanks Karl. Exactly what I was going for. -Nick On May 5, 9:29 am, Karl Swedberg wrote: > Sorry, I must have misunderstood the context. I was responding to this: > > > Don't use .text(), you'll get an array-like object of text nodes > > It seemed like you were saying that .text() retur

[jQuery] Re: How to select all text in a div except ul

2009-05-05 Thread mkmanning
Yeah, sorry for the confusion; I should type more slowly :P That does read badly. Should be "don't use .text()". Period. Using my original example, you'll get an array-like object... Thanks for pointing that out though, I wouldn't want to confuse anyone. On May 5, 9:29 am, Karl Swedberg wrote

[jQuery] Re: How to select all text in a div except ul

2009-05-05 Thread Karl Swedberg
Sorry, I must have misunderstood the context. I was responding to this: Don't use .text(), you'll get an array-like object of text nodes It seemed like you were saying that .text() returns an array-like object. But if it's used as a getter (without an argument), it returns a string. If th

[jQuery] Re: How to select all text in a div except ul

2009-05-04 Thread mkmanning
Sorry, maybe my response was somewhat confusing, but I don't believe you'll get a concatenated string (as the OP's followup indicates). After using .filter(), you'll get an array-like object (it's still the jQuery object) which contains the text nodes. Calling .text() on those won't actually conc

[jQuery] Re: How to select all text in a div except ul

2009-05-04 Thread nick
That still seems to only return an object rather than a string. This works though... alert($('div').clone().children().remove().end().text()); Is there a better way to get a string than that? On May 2, 6:28 pm, mkmanning wrote: > Don't use .text(), you'll get an array-like object of text nod

[jQuery] Re: How to select all text in a div except ul

2009-05-03 Thread Karl Swedberg
On May 2, 2009, at 9:28 PM, mkmanning wrote: Don't use .text(), you'll get an array-like object of text nodes. Tiny clarification: you'll get a concatenated string of text nodes. --Karl Karl Swedberg www.englishrules.com www.learningjquery.com On May 2, 2009, at 9:28 PM, mkm

[jQuery] Re: How to select all text in a div except ul

2009-05-02 Thread mkmanning
Don't use .text(), you'll get an array-like object of text nodes. Try var text = $('div').contents().filter(function(){return this.nodeType==3;}); console.log(text) On May 2, 6:06 pm, nick wrote: > Thanks for the response. Are you sure thats correct though? > > alert($('div').contents().filter

[jQuery] Re: How to select all text in a div except ul

2009-05-02 Thread nick
Thanks for the response. Are you sure thats correct though? alert($('div').contents().filter(function(){return this.nodeType==3;}).text()); returns empty.

[jQuery] Re: How to select all text in a div except ul

2009-05-01 Thread mkmanning
To get just the text nodes: $('div').contents().filter(function(){return this.nodeType==3;}); If you want to filter out 'empty' nodes: $('div').contents().filter(function(){return this.nodeType==3 && this.nodeValue.replace(/\W/g,'')!='';}); Take it from there :) On May 1, 4:06 pm, nick wrote: