<?xml version="1.0" encoding="UTF-8"?>
<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom">
  <id>tag:www.refactormycode.com,2007:users732</id>
  <link type="application/atom+xml" href="http://www.refactormycode.com/users/732" rel="self"/>
  <title>jp.stacey</title>
  <updated>Sun Jun 29 21:32:17 -0700 2008</updated>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor12159</id>
    <published>2008-06-29T21:32:17-07:00</published>
    <title>[JavaScript] On [jQuery] All descendent text nodes within a node</title>
    <content type="html">&lt;p&gt;From what you say, you only need the descendants, not the starting node(s). So you can get it a bit smaller (and a little bit quicker) by removing one of your two function() blocks. How does this look to you?&lt;/p&gt;

&lt;p&gt;You might get even quicker by using this.childNodes (which is what jQuery's contents() function uses internally), as long as you don't need to worry about iframes.&lt;/p&gt;

&lt;pre&gt;$.fn.textNodes = function() {
  var ret = [];
  this.contents().each( function() {
    var fn = arguments.callee;
      if ( this.nodeType == 3 || $.nodeName(this, &amp;quot;br&amp;quot;) ) 
        ret.push( this );
      else $(this).contents().each(fn);
  });
  return $(ret);
}
&lt;/pre&gt;</content>
    <author>
      <name>jp.stacey</name>
      <email>jp.stacey@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/341-jquery-all-descendent-text-nodes-within-a-node/refactors/12159" rel="alternate"/>
  </entry>
</feed>

