jQuery: Get the text value of a node without it’s children

Use the following code to get the text value of a node without the text content of it’s children (unlike jQuery’s text() method):

var node = $('#selector'),
    text = $.trim(node[0].childNodes[0].nodeValue);

var hastext = text.length > 0;