javascript - How do I target strings that have words in all caps? -


i'm trying change background color on strings contain text styles (using javascript). example, want make text doesn't contain caps have green background , string contains word that's caps have red background.

i know i'd need use conditional if statement i'm not sure how can achieve desired.

below link js fiddle. thoughts appreciated. thanks!

http://jsfiddle.net/gnxcr/

-d

basically, split string words, loop through words, in each word loop through each letter , check if uppercase checking if letter , letter.tolowercase() different. this:

function hasallcapsword(string) {     var words=string.split(" ");      (var i=0;i<words.length;i++) {         var letters=words[i].split("");         var wordisallcaps=false;          (var j=0;j<words.length;j++) {             if (letters[j] && letters[j]!=letters[j].tolowercase()) {                 wordisallcaps=true;             }         }          if (wordisallcaps) return true;     }      return false; } 

Comments

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -