JamesBrownIsDead
JamesBrownIsDead

Reputation: 4715

JavaScript: DOM text nodes

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>

Upvotes: 1

Views: 1271

Answers (2)

meouw
meouw

Reputation: 42140

//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

Upvotes: 0

gregseth
gregseth

Reputation: 13438

With jQuery:

Edit:

$('#foobar').get(0).firstChild.data;

Upvotes: 1

Related Questions