As follows from your post, if you want to create your own method .nextText(), simply enter the following brother into the property property of the DOM element: nodeValue
$.fn.nextText = function() {
return this.length ? this[0].nextSibling.nodeValue : null;
};
.eq(), :
var text = $('.more').eq(0).nextText();
console.log(text); // (TEXT 1)
, , :
$.fn.nextText = function(index) {
return this.length ? this[index || 0].nextSibling.nodeValue : null;
};
var text = $('.more').nextText(1);
console.log(text);
( OP ), .nextTextUntil():
$.fn.nextTextUntil = function(until) {
var text = '', next;
if (this.length) {
next = this[0].nextSibling;
while (next !== null && until && !$(next).is(until)) {
text += next.nodeValue || next.textContent;
next = next.nextSibling;
}
}
return text;
};
:
$('.more').eq(0).nextTextUntil('.more');
:
(TEXT 1 MORE TEXT)
HTML:
<a class="more" href="/e1">Event 1</a> (TEXT 1 <em>MORE TEXT</em>)