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"

Leave a Reply

Your email address will not be published.

2 × = 18

This site uses Akismet to reduce spam. Learn how your comment data is processed.