For sure, childNodes is the way to go if its always constantly going
to be like that, another possibility is to regex it

$("p").html().match(/.+(?=<.+?>.+<\/.+?>)/)

and if you wanted <p> text on the other side of the span you could do
it like this ** javascript regex doesn't support lookbehind so you
have to reverse the string to get a similar effect, making it rather
lengthy **

String($("p").html().split("").reverse().join("").match(/.+(?=>.+?\/<.
+>.+?<)/)).split("").reverse().join("")

assign the first to var a and the second to var b then combine the
strings.

On Sep 30, 4:56 pm, ricardobeat <[EMAIL PROTECTED]> wrote:
> If you are 100% sure that the <span> will always come AFTER the text
> data, like your example format, you could simply do:
>
> $('#paragraph')[0].childNodes[0];
>
> or
>
> $('p').each(function(){
>    var data = this.childNodes[0];
>
> });
>
> - ricardo
>
> On Sep 30, 5: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

Reply via email to