cl0udc0ntr0l
cl0udc0ntr0l

Reputation: 149

Changing font of Specific Characters

I'm trying to make an effect where all the vowels are in a different font from the consonants.

Is there a way to select only 'a, e, i, o, u' and apply .css("font-family", "mycustomfont");

Trying to avoid having to out all the vowels. All suggestions appreciated!

Upvotes: 1

Views: 2221

Answers (2)

inhan
inhan

Reputation: 7470

str = str.replace(/([aeiou]+)/g,'<span class="etc">$1</span>');

Upvotes: 0

elclanrs
elclanrs

Reputation: 94101

http://jsfiddle.net/elclanrs/rAKvB/

var str = 'Hello World',
    letters = '';

for (var i = 0, len = str.length; i < len; i++) {
    if (str[i].match(/[aeiou]/i)) {
        letters += '<span class="vowel">' + str[i] + '</span>';
    } else {
        letters += '<span class="consonant">' + str[i] + '</span>';
    }
}

Upvotes: 3

Related Questions