Created
January 16, 2024 19:40
-
-
Save makbeta/31e5900b4abd758cddc5bc08eefc1ea2 to your computer and use it in GitHub Desktop.
Wrap DOM text nodes into spans
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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