views:

87

answers:

2

Take a look at the snippet below. Does it create a text node for the string "test" in the DOM? Can I select that node with jQuery for MooTools?

<div id="foobar">
    test <img />
</div>
A: 

With jQuery:

Edit:

$('#foobar').get(0).firstChild.data;
gregseth
Nope, doesn't work.
JPot
Ok, my bad, see the edit for a working one.
gregseth
A: 
//plain
var node = document.getElementById('foobar').childNodes[0];

//jquery
$("foobar").contents().eq(0);

this will give you a textnode which will include the whitespace around the text too

meouw