FoxNews Element Title/Summary Test

by nickadeemus2002

HTML

<div id="summary100"></div>
<div id="summaryWords"></div>

CSS

#summary100{border:1px solid #585858;background-color:#eee;}
#summaryWords{background-color:#ff0000;color:#fff;}

JavaScript

var wordRegEx =  /([A-Za-z0-9']+)(\s)/gi;


var title = "Sandusky Admits Showering With Boys, but Says He's 'Innocent' of Sex Abuse Charges";
var title60 = title.substring(0,60);
var titleWords = title60.match(wordRegEx);

var summary="Sandusky's arrest earlier this month on charges he sexually abused at least eight boys has rocked Penn State, which fired the university president, as well as legendary football coach Joe Paterno, after criticism that they didn't go to police sooner with what they new about the allegations.&#160;";

var summary100 = summary.substring(0, 100);
var summaryWords = summary100.match(wordRegEx);

// If the last letter was part of a word
if( summary[101].match(wordRegexp) ) {
    // Throw out the last word (since it was incomplete)
    summaryWords.pop();
}
var test = summaryWords.join(" ")+"...";
$(document).ready(function(){
    $("#summary100").html(summary100);
    $("#summaryWords").html(test);
});