Is there an equivalient of the firstChild.data in JQuery?
Given the following HTML :
<p id='test'>Hello<span>world</span>/<p>
the below javascipt will return : "Hello"
document.getElementById('test').firstChild.data
the given JQuery will return : Hello< span>world</span>
$('#test').text()
how can I achieve this?
You want a text node, so you can make use of .contents:
$("#test").contents().first().text();
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