Q:

Underline all the words of a text using jQuery

0

Underline all the words of a text using jQuery.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

HTML Code :

<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-git.js"></script>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
 <title>Underline all words of a text through jQuery</title>
 </head>
 <body>
 <p>The best way we learn anything is by practice and exercise questions. Here you have the opportunity to practice the Java programming language concepts by solving the exercises starting from basic to more complex exercises.</p>
 </body>
 </html>

CSS Code :

p span{
    text-decoration: underline;
  }

JavaScript Code :

$('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>');
			}
		}
	
	});

});

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now