Selecting a first-level text element ".text ()" without selecting child elements
I have the following html
<label>
outer
<span>inner</span>
</label>
I want to replace the “outer” value, leaving the range with its “inner” text intact. Using
$('label').text('new outer');
replaces the entire contents of the label (along with the range). Is there a great way to just select the text block "external" without adding extra spaces or redoing things such as saving the value of the inner interval of the label and its subsequent reuse?
Text node , span ( Text):
$("label").contents().each(function() {
// Within this iterator function, jQuery sets `this` to be
// each child node (including Text nodes, not just Elements)
if (this.nodeType === 3) { // 3 = text node
this.nodeValue = "updated ";
return false;
}
});
, , . Text node () node.nodeValue, , (, ), ; , , ..