1

I want to recognize all objects in my web page that contains at least one UNICODE character.

By this way, I want to perform a specific CSS class to those elements that has UNICODE characters (maybe they are completely UNICODE or maybe they are contain NON-UNICODE & UNICODE together. For example a div that has English and Arabian.)

Is there any way in order to do this via JQUERY in client side of browsers?

Please guide me.

Thanks a lot.

Mehrdad201
  • 121
  • 9
  • A similar (but not duplicate) question was asked, which I think may be useful: http://stackoverflow.com/questions/147824/javascript-how-to-find-whether-a-particular-string-has-unicode-characters-esp – Surreal Dreams May 02 '12 at 13:35
  • it is a good idea. I tested it. it works. but don't you thing that this solution may have problem [such as low speed or overload] for long pages ??? – Mehrdad201 May 02 '12 at 14:15

2 Answers2

2

(All text in a web browser is Unicode, by definition. You probably mean to detect Unicode characters that are not also ASCII characters.)

You would have to walk over all elements and check their text with a regex, for example:

$('*').each(function() {
    if (/[\u0080-\uFFFF]/.test($(this).text()))
        $(this).addClass('hasnonascii');
});

this will be slow. It's also recursive, so eg you'll get a class="hasnonascii" on <body> if there's any non-ASCII content on the page.

bobince
  • 528,062
  • 107
  • 651
  • 834
0

You can use XRegExp with the unicode plugin to write a regular expression to check for unicode characters within the text of certain elements.

Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339