Skip to content

Instantly share code, notes, and snippets.

@makbeta
Created January 16, 2024 19:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save makbeta/31e5900b4abd758cddc5bc08eefc1ea2 to your computer and use it in GitHub Desktop.
Save makbeta/31e5900b4abd758cddc5bc08eefc1ea2 to your computer and use it in GitHub Desktop.
Wrap DOM text nodes into spans
const $element = $('#my-element');
const $nodes = $element.contents();
$nodes.each(function(index, element) {
const $el = $(element);
if(element.nodeType === 3 && $.trim($el.text())) {
$el.wrap('<span class="orphan" />');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment