Skip to content

Instantly share code, notes, and snippets.

@tieutantan
Last active December 18, 2020 04:24
Show Gist options
  • Save tieutantan/dba0f8402c57627d91823558ed28f6d5 to your computer and use it in GitHub Desktop.
Save tieutantan/dba0f8402c57627d91823558ed28f6d5 to your computer and use it in GitHub Desktop.
English in text detection JS
function changeEngFont(selector) {
$(selector).contents().each(function () {
if (this.nodeType === 3) {
} else {
let value = this.innerHTML;
let isEnglish = value.search(/[^a-zA-Z]+/);
if(isEnglish === -1 || isEnglish === 3) {
$(this).css("font-family", "Baskerville, serif");
}
}
});
}
changeEngFont(".content-box"); // shop pane
changeEngFont("#shop_single .text"); // shop single
changeEngFont(".slider-title"); // home slider
<div class="slider-title">
<p class="caption"><?php echo $slide->title; ?></p>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment