Thomas R Alexander

Manager, Developer, and professional problem solver

jQuery Plugin: Find text within selector element(s) that matches specified language and wrap it in a span[lang=langauge]

Sometimes character encoding detection in the back-end of software can be difficult. Here is a quick solution to do it in JavaScript! I’ve implemented a jQuery plugin that accepts selectors and a language, iterates through the .text() of the selectors, and wraps the text in a <span lang=””> where the lang attribute matches the language passed in. With this code, you can change fonts, apply specific actions to text (right to left or left to right), etc…

Here is an example CSS:

Currently, only hebrew and english are defined in the plugin by default, but you can pass in additional languages in the options object when you call the function. The function parameter expects an object that contains these keys

Here’s an example on how you’d call the function:

Download the code from GitHub

Leave a Reply

Your email address will not be published. Required fields are marked *.

You may use these <abbr title="HyperText Markup Language">HTML</abbr> tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">