... uhm ... another if in the main function and for a "weird" case ... I am not sure it is worth it ... text nodes cannot handle most of the jQuery stuff so maybe it makes sense to apply your suggestion:
function doTextManipulation(elem) { var text = elem && elem.nodeType === 3 ? elem.nodeValue : $(elem).text(); return /* my text manipulation algorithm */ } Regards On Tue, Nov 17, 2009 at 2:07 PM, Xavi Ramirez <xavi....@gmail.com> wrote: > What I presented was a simplified example to better illustrate my > question. Here's a more realistic example: > > function doTextManipulation(elem) { > var text = $(elem).text(); > > return /* my text manipulation algorithm */ > } > > The function above fails when a text node is passed in due to the fact > $().text() returns an empty string for all text nodes. > > I personally believe this is a bug, but I could be wrong. This is why > I'm asking if $(document.createTextNode("test")).text() is expected to > return an empty string. > > If this is an actual, then the fix is as simple as adding > if(text.nodeType === 3) { return text.nodeValue; } to the text > function in > http://github.com/jquery/jquery/blob/master/src/manipulation.js > (around line 36). > > I hope this clears things up a bit. > > Thanks, > Xavi > > On Tue, Nov 17, 2009 at 8:36 AM, Andrea Giammarchi > <andrea.giammar...@gmail.com> wrote: > > I miss the "feature" here. > > You create a textNode and you know what is its content since you are > > creating it. > > Even if it was to chain the text assignment looks more like extreme > laziness > > ... am I am missing something about this request? > > > > On Mon, Nov 16, 2009 at 9:18 PM, Xavi <xavi....@gmail.com> wrote: > >> > >> Hello, > >> > >> Currently $(document.createTextNode("test")).text() returns empty > >> string. Is this expected? > >> > >> Thanks, > >> Xavi > >> > >> -- > >> > >> You received this message because you are subscribed to the Google > Groups > >> "jQuery Development" group. > >> To post to this group, send email to jquery-...@googlegroups.com. > >> To unsubscribe from this group, send email to > >> jquery-dev+unsubscr...@googlegroups.com<jquery-dev%2bunsubscr...@googlegroups.com> > . > >> For more options, visit this group at > >> http://groups.google.com/group/jquery-dev?hl=. > >> > >> > > > > -- > > > > You received this message because you are subscribed to the Google Groups > > "jQuery Development" group. > > To post to this group, send email to jquery-...@googlegroups.com. > > To unsubscribe from this group, send email to > > jquery-dev+unsubscr...@googlegroups.com<jquery-dev%2bunsubscr...@googlegroups.com> > . > > For more options, visit this group at > > http://groups.google.com/group/jquery-dev?hl=. > > > > -- > > You received this message because you are subscribed to the Google Groups > "jQuery Development" group. > To post to this group, send email to jquery-...@googlegroups.com. > To unsubscribe from this group, send email to > jquery-dev+unsubscr...@googlegroups.com<jquery-dev%2bunsubscr...@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/jquery-dev?hl=. > > > -- You received this message because you are subscribed to the Google Groups "jQuery Development" group. To post to this group, send email to jquery-...@googlegroups.com. To unsubscribe from this group, send email to jquery-dev+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/jquery-dev?hl=.