Hmm.. that seems like a dead end in jQuery, it can't handle Text
objects obtained from text nodes.

either text(), html() or contents() return nothing. We're left with
two text objects to which we can't do anything useful. The only way I
found to get the text is

$('p').contents().filter("[nodeType=3]").clone().wrapAll('<div/
>').parent().html()

but that is both stupid and destructive... text() should be able to
handle Text objects.

On Oct 3, 2:30 pm, ricardobeat <[EMAIL PROTECTED]> wrote:
> Just found a different way of doing this:
>
> var text = $('#tes').contents().filter("[nodeType=3]");
>
> http://docs.jquery.com/Traversing/contentshttp://www.w3schools.com/Dom/dom_nodetype.asp
>
> - ricardo
>
> On Oct 3, 11:37 am, Michael <[EMAIL PROTECTED]> wrote:
>
> > Those methods are destructive though.
> > A co-worker just came up with this very nice solution:
>
> > alert($('#test').clone().children().remove().end().text());
>
> > =================================================================================
> > On Oct 3, 10:09 am, "Mauricio \(Maujor\) Samy Silva"
>
> > <[EMAIL PROTECTED]> wrote:
> > > 1-) alert($('*', $('p')).remove().text())
> > > 2-) alert($('*', $('p')).empty().text())
>
> > > $('*', $('p')) // contextual selector: finds all HTML elements inside the
> > > paragraphs.
> > > Chain with empty() ou remove() according your  needs
>
> > > Maurício
>
> > > > Is there a more elegant, concise, pure jQuery approach to doing the
> > > > following?...
>
> > > > HTML:  <p id="test">paragraph_text<span>span_text</span></p>
>
> > > > JAVASCRIPT:
> > > > var p_txt = $('#test').text().substring(0, ($('#test').text().length -
> > > > $('#test span').text().length));
> > > > alert(p_txt);
>
> > > > OUTPUT:  paragraph_text

Reply via email to