var words=$("#yourTextContainer").text().split(' ');
$("#yourTextContainer").html("");
$.each(words, function(i,val){
$('<span/>').text(val+" ").appendTo("#yourTextContainer");
});
$("#yourTextContainer span").live("mouseover",function(){
$(this).css("background-color","yellow");
});
$("#yourTextContainer span").live("mouseout",function(){
if($(this).css("background-color") !="rgb(0, 0, 255)")
{
$(this).css("background-color","white");
}
});
$("#yourTextContainer span").live("click",function(){
$("#yourTextContainer span").css("background-color","white");
$(this).css("background-color","blue");
var text = $(this).text();
});
EDIT: see example http://jsfiddle.net/aD5Mu/
source
share