getting all textnodes in a frame

getting all textnodes in a frame

  1. Hi,

I'm trying to get all textnodes in an iframe, like this:
  1. $("*", $(frame).contents()).each(function(){
  2. if($(this).nodeType==3)
  3.             $(this) .wrap(<span/>); 

  4. });

But it seems not to be Working as I get only nodes type 1.

I have some elements like this:

  1. <span><span>this is a node type 1</span>this a text node</span>

  2. I want the elements not to have any textnodes as childnodes. i.e., If an element has children, I want all those children to be type 1.

  3. I want the above element to be:
  4. <span><span>this is a node type 1</span><span>this a text node </span> </span>

Thanks,

Regards