Wrap Emojis
🧩 Syntax:
<script>
$(document).ready(function() {
// Regular expression to match most emojis
var emojiRegex = /([\u2700-\u27BF]|[\uE000-\uF8FF]|\uD83C[\uDC00-\uDFFF]|\uD83D[\uD000-\uDFFF]|\uD83E[\uDD00-\uDDFF])/g;
// Function to wrap emojis in a span
function wrapEmojis(element) {
$(element).contents().each(function() {
if (this.nodeType === 3) { // Node type 3 is a text node
var replacedText = this.nodeValue.replace(emojiRegex, '<span class="emoji">$1</span>');
if (replacedText !== this.nodeValue) {
$(this).replaceWith(replacedText);
}
} else if (this.nodeType === 1) { // Node type 1 is an element
wrapEmojis(this); // Recursive call for each element
}
});
}
// Call the function on the body or any specific part of the page
wrapEmojis('body');
});
</script>