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
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
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
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
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
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
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
Thanks for the response. Are you sure thats correct though?
alert($('div').contents().filter(function(){return
this.nodeType==3;}).text());
returns empty.
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:
9 matches
Mail list logo