<html>
<head>
<script
src = "https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$('p').each(function()
{
var
text_words = $(this).text().split(' ');
$(this).empty().html(function()
{
for
(i = 0; i < text_words.length; i++) {
if
(i === 0) {
$(this).append('<span>'
+ text_words[i] + '</span>');
}
else {
$(this).append('
<span>' + text_words[i] + '</span>');
}
}
});
});
});
</script>
<style
type="text/css">
p
span
{
text-decoration:
underline;
}
</style>
</head>
<body>
<p>
To underline all the words of a text</p>
<p>
To underline all the words of a text</p>
<p>
To underline all the words of a text</p>
</body>
</html>