JSFiddle - React, Tailwind, and code Playground

by RVAProgrammer

HTML

<p>
    <label>item 1</label>Capture me!
    <br>
    <br>
    <label>item 3</label>Capture me 2 !
    <br>
    <br>
    <label>item 2</label>Don't capture me</p>

CSS

label {
    display:inline-block;
    width:25%;
    font-weight:bold;
}
p {
    font-family:arial;
}

JavaScript

console.log($('p').contents().filter(function () {
    var isTextNode = this.nodeType === Node.TEXT_NODE

    if (isTextNode) {

        if ($(this)[0].nextElementSibling === null) {
            return false;
        }

        return true;
    }
    
    return false;
}).text());