I'm using this code:
/**
 * Get Text Nodes from an Element
 * Returns and object unless number is passed in
 * Numbers is 0 based
 */
(function( $ ) {
$.fn.textNodes = function(number) {
    var nodes = jQuery(this).contents().filter(function(){
        return this.nodeType == 3;
    });
    if(jQuery.isNumber(number)){
        return nodes[number];
    }
    return nodes;
};
})( jQuery );
It's used to grab the text nodes out of html
For example:
<div>
    <span>Testing</span>
    What is this?
</div>
I'm looking for What is this?
This works, as I can do a console.log and see the result in the console.
But when I try and use the result in an input field it give me: [object Text]
How can I use the result as a string value?
I've tried toString() but that gives the same result, unless I missed something.
Use the nodeValue property:
$("#yourInputField").val(yourTextNode.nodeValue);
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With