diff --git a/js/halfstyle.js b/js/halfstyle.js index b3d1cb4..dc43886 100644 --- a/js/halfstyle.js +++ b/js/halfstyle.js @@ -3,13 +3,22 @@ * Copyright 2014 Arbel Hakopian * Licensed under MIT (https://github.com/arbelh/HalfStyle/blob/master/license.md) */ -$(document).ready(function(){ - var textToHalfStyle = $('.textToHalfStyle').text(); - var textToHalfStyleChars = textToHalfStyle.split(''); - var hiddenTextForAccessibility = $('.textToHalfStyle').text(); // preserve text for accessibility, like audio screen readers or brail readers for the blind or visually impaired - $('.textToHalfStyle').html(''); - $('.textToHalfStyle').append('' + hiddenTextForAccessibility + ''); //append the text for accessibility - $.each(textToHalfStyleChars, function (i, v) { //for accessibility, aria-hidden="true" will prevent the text from being seen by screen readers - $('.textToHalfStyle').append(''); - }); +jQuery(function($) { + var text, chars, $el, i; + + // Iterate over all class occurences + $('.textToHalfStyle').each(function(idx, el) { + $el = $(el); + text = $el.text(); + chars = text.split(''); + + // Set the screen-reader text + $el.html('' + text + ''); + + // Iterate over all chars in the text + for (i = 0; i < chars.length; i++) { + // Create a styled element for each character and append to container + $el.append(''); + } + }); });