Using jQuery. I have the following html:
All the world
How w
Just to toss in a example to a way old question, wrap text in a label
$('input[type="checkbox"]')
.each(function(index, el) {
var textNode = $(el.nextSibling);
if (textNode[0].nodeType == Node.TEXT_NODE) {
let checkwrap = $(el).wrap('').closest('.found');
textNode.appendTo(checkwrap);
}
});
.found {
border: solid cyan 1px;
color: blue;
padding: 0.5em;
display: inline-block;
margin: 0.3em;
}
label.found {
color: lime;
}
in a span
All the world
All the world 2 in a span
All the world 3 in a span
All the world 4in a span also
there, wrapped in a label, oh wait, that is an answer, just have to get the nextSibling
isolated by type