you can let the var go:

$('p').each(function(){
   if (this.firstChild.nodeName.toLowerCase() !="span")
      $(this.firstChild).wrap("<b/
>").parent().css('color','red');
 });

and less fail-safe but shorter (can catch the span if there is no text
and the span is also empty):

$('p').each(function(){
   if (!this.firstChild.hasChildNodes())
      $(this.firstChild).wrap("<b/
>").parent().css('color','red');
 });

au revoir

- ricardo

On Sep 30, 7:22 pm, Pedram <[EMAIL PROTECTED]> wrote:
> Dear folks ,
> finally this is what I got
>
> $(p).each(function(){
>         if(this.childNodes[0].nodeName.toLowerCase() !="span")
>             var newNode=$(this.childNodes[0]).wrap("<b/>");
>             newNode.css('color','red');
>  });
>
> this is the shortest code , basically you can not treat as a SELECTOR
> to a Text which is not in the Tag so everything goes Wrong Unless be
> get the text with the jQuery and then Wrap it with a Tag after that it
> is ready to do what ever We want if make it workable
> in this 3 Line
> 1- all P has been Filter
> 2- all Children which are not in the Span are FIlter
>  ----RIght now we can not do something like this  $(.....).css(...) ;
> because our Text is not a Selecter so
> 3- we Wrap it with what ever we want and now it is ready for you to
> work with it
>
> thanks a Lot Equally... and other Guys basically we could not work
> with a text which is not Wrapped in a Tag ...
>
> On Sep 30, 11:34 pm, equallyunequal <[EMAIL PROTECTED]> wrote:
>
> > Here's a better version of 
> > that:http://joeflateau.net/playground/testingpexcspan2.html
>
> > $( function(){
> >         console.log($($
> > ("p").childNodesExclusive("span")).allDOMNodesToHTML());
>
> > });
>
> > // this function returns all child nodes for the given element,
> > excluding those that have a property that matches
> > jQuery.fn.childNodesExclusive = function(exclude, caseSensitive,
> > DOMProperty) {
> >         DOMProperty = DOMProperty || "nodeName";
> >         caseSensitive = (typeof caseSensitive != 'undefined') ?
> > caseSensitive : false;
>
> >         exclude = (!caseSensitive) ? exclude.toLowerCase() : exclude;
>
> >         var nodes = [];
>
> >         $(this).each( function() {
> >                 $.each(this.childNodes, function(i, node) {
> >                         var compare = (!caseSensitive) ? 
> > node[DOMProperty].toLowerCase() :
> > node[DOMProperty];
> >                         if (exclude != compare) { nodes[nodes.length] = 
> > node; }
> >                 });
> >         });
>
> >         return nodes;
>
> > }
>
> > // this function converts all nodes to html, including text nodes
> > // and ignoring invisible nodes
> > jQuery.fn.allDOMNodesToHTML = function() {
> >         var valueTypeNodes = [
> >                 document.TEXT_NODE,
> >                 document.ATTRIBUTE_NODE,
> >                 document.CDATA_SECTION_NODE
> >         ]
> >         var ignoreNodes = [
> >                 document.PROCESSING_INSTRUCTION_NODE,
> >                 document.COMMENT_NODE
> >         ]
>
> >         var html = "";
>
> >         this.each( function(i, node){
> >                 if ($.inArray(node.nodeType, ignoreNodes) > -1) {
> >                         //do nothing
> >                 } else if ($.inArray(node.nodeType, valueTypeNodes) > -1) {
> >                         html += node.nodeValue;
> >                 } else {
> >                         html += node.innerHtml;
> >                 }
> >         });
>
> >         return html;
>
> > }
>
> > On Sep 30, 3:01 pm, equallyunequal <[EMAIL PROTECTED]> wrote:
>
> > > NodeType        Named Constant
> > > 1       ELEMENT_NODE
> > > 2       ATTRIBUTE_NODE
> > > 3       TEXT_NODE
> > > 4       CDATA_SECTION_NODE
> > > 5       ENTITY_REFERENCE_NODE
> > > 6       ENTITY_NODE
> > > 7       PROCESSING_INSTRUCTION_NODE
> > > 8       COMMENT_NODE
> > > 9       DOCUMENT_NODE
> > > 10      DOCUMENT_TYPE_NODE
> > > 11      DOCUMENT_FRAGMENT_NODE
> > > 12      NOTATION_NODE
>
> > > from:http://www.w3schools.com/Dom/dom_nodetype.asp
>
> > > I had to check for nodeType == 3 since the text nodes do not have an
> > > innerHtml property. Also, after some reading, I think 'node.nodeValue'
> > > would be more "proper" over 'node.data'
>
> > > I'd like to see how you get it to work better with jQuery, or rather,
> > > "native jQuery". I'll try it myself, but I'd like to see how others
> > > would implement it.
>
> > > On Sep 30, 2:20 pm, Pedram <[EMAIL PROTECTED]> wrote:
>
> > > > Wow amazing... it worked let me ask you question I think I can do it
> > > > with jQuery ..
> > > > do you know what does node.nodeType mean in javascript
> > > > nodeType=1 what does that mean for each value ?
> > > > thanks Pedram
>
> > > > On Sep 30, 8:29 pm, equallyunequal <[EMAIL PROTECTED]> wrote:
>
> > > > > I'm not sure how to do it in a "jQuery" way. But here's what I came up
> > > > > with:
>
> > > > > $( function(){
> > > > >         $("p").each( function() {
> > > > >                 var allButSpan = this.allButSpan = new Array();
> > > > >                 $.each(this.childNodes, function(i, node) {
> > > > >                         if (node.nodeName.toLowerCase() != "span")
> > > > > { allButSpan[allButSpan.length] = node; }
> > > > >                 });
> > > > >         });
>
> > > > >         $("p").each( function(){
> > > > >                 var innerHtml = "";
> > > > >                 $.each(this.allButSpan, function(i, node) { innerHtml 
> > > > > +=
> > > > > (node.nodeType == 3) ? node.data : $(node).html(); } );
> > > > >                 console.log(innerHtml);
> > > > >         });
>
> > > > > });
>
> > > > > Example here:http://joeflateau.net/playground/testingpexcspan.html
>
> > > > > You need Firebug (or anything that supports console.log) to use the
> > > > > example!
>
> > > > > On Sep 30, 12:20 pm, Pedram <[EMAIL PROTECTED]> wrote:
>
> > > > > > It didn't work Cause the Text isn't concern as a Children and it is 
> > > > > > in
> > > > > > No Tag area ....  so when we call $(this).children it returns only 
> > > > > > the
> > > > > > Span and if we do $(this).children(":not(span)") it returns NULL ...
> > > > > > so Equally..... what should we do
>
> > > > > > On Sep 30, 5:34 pm, equallyunequal <[EMAIL PROTECTED]> wrote:
>
> > > > > > > Ok, how about something to the effect of:
>
> > > > > > > $("p").each(function() { $
> > > > > > > (this).children(":not(span)").css({color:"red"}); });
>
> > > > > > > On Sep 30, 8:12 am, [EMAIL PROTECTED] wrote:
>
> > > > > > > > If I do this with CLone then all my prossesing is with the 
> > > > > > > > clone but I
> > > > > > > > need to have a selector in the Original one not in the Clone so
> > > > > > > > changing and modifying the clone is not necessary ,the only way 
> > > > > > > > is get
> > > > > > > > a Clone of THe Span Then Remove the Span and then get the 
> > > > > > > > content of
> > > > > > > > the P do some changes on it , after that add the Span again And 
> > > > > > > > I
> > > > > > > > think this is not the right way to Deal with this ...
> > > > > > > > I'm still working on thiws and waiting for the best way to it
> > > > > > > > Thanks Pedram
>
> > > > > > > > On Sep 30, 7:36 am, equallyunequal <[EMAIL PROTECTED]> wrote:
>
> > > > > > > > > $("p:not(span)") would select all paragraphs that are not 
> > > > > > > > > spans...
> > > > > > > > > which would be all paragraphs even if they have a child that 
> > > > > > > > > is a
> > > > > > > > > span.
> > > > > > > > > $("p :not(span)") or $("p *:not(span)") would select all 
> > > > > > > > > paragraphs
> > > > > > > > > without child spans... which would be none of the paragraphs.
>
> > > > > > > > > He needs the contents of all paragraphs minus the content of 
> > > > > > > > > a span.
> > > > > > > > > The only way (I can think of) to non-destructively get the 
> > > > > > > > > contents of
> > > > > > > > > an element minus some of its children is to clone it first, 
> > > > > > > > > then
> > > > > > > > > remove the children.
>
> > > > > > > > > On Sep 29, 3:33 pm, dasacc22 <[EMAIL PROTECTED]> wrote:
>
> > > > > > > > > > um cant you just do something like $("p:not(span)") ??
>
> > > > > > > > > > On Sep 28, 3:48 pm, equallyunequal <[EMAIL PROTECTED]> 
> > > > > > > > > > wrote:
>
> > > > > > > > > > > This should work:
>
> > > > > > > > > > > var clone = $("p").clone();
> > > > > > > > > > > clone.find("span").remove();
>
> > > > > > > > > > > clone.each( function() { console.log(this) } );
>
> > > > > > > > > > > On Sep 28, 2:13 pm, [EMAIL PROTECTED] wrote:
>
> > > > > > > > > > > > Hi Guys,
>
> > > > > > > > > > > > this is the Code which I am working on
>
> > > > > > > > > > > > <p>
> > > > > > > > > > > >   Data which I need to select and it hasn't  an 
> > > > > > > > > > > > attribute
> > > > > > > > > > > >   <span> Data in a Span </span>
> > > > > > > > > > > > </p>
> > > > > > > > > > > > <p>
> > > > > > > > > > > >   Data which I need to select and it hasn't  an 
> > > > > > > > > > > > attribute
> > > > > > > > > > > >   <span> Data in a Span </span>
> > > > > > > > > > > > </p>
> > > > > > > > > > > > <p>
> > > > > > > > > > > >   Data which I need to select and it hasn't  an 
> > > > > > > > > > > > attribute
> > > > > > > > > > > >   <span> Data in a Span </span>
> > > > > > > > > > > > </p>
> > > > > > > > > > > > How could FIlter and Select the text Before the <span>
> > > > > > > > > > > > does someone has an Idea ?

Reply via email to