Archive for September, 2022

Get the text node of an element

var h1_text = $('h1').contents().filter(function() { return this.nodeType === Node.TEXT_NODE; }).text();
<h1>Lorem ipsum <span>dolor sit amet</span><h1>

// console.log(h1_text) -> "Lorem ipsum"