I'm trying to wrap a class around the first or the second half of a headline so that I could create more dynamic and cool headlines with jQuery.
In theory I want to find all of the spaces in the sentence and divide it into two. If the headline contains an uneven number of words the script should detect that and also add the class to the nearest word.
Nice one @lashleigh. You can have a look at a working example here:
http://jsfiddle.net/johnhunter/KRJdm/
@Tony, I've implemented what you are after as a jquery plugin. You call it on the header you want formatted:
...and it will produce html output like this:
Before:
After:
UPDATED:
Not part of the original question but I have updated the example to allow you to specify at which word the wrapping occurs. If you provide an index argument it will use that offset on the list of words (minus values count back from the end). e.g:
http://jsfiddle.net/johnhunter/KRJdm/