Write a jQuery code to underline all the words of a text.

 Write a jQuery code to underline all the words of a text.

Write a jQuery code to underline all the words of a text.

Answer :
File Name : jQuery.html

<html>
    <head>
        <script src="https://code.jquery.com/jquery-3.6.0.js" integrity="sha256-H+K7U5CnXl1h5ywQfKtSj8PCmoN9aaq30gDh27Xc0jk=" crossorigin="anonymous"></script>
        <title>SP Creation</title>
    </head>
    <body>
        <div id="box">
            <h2>jquery</h2>
        </div>
        <div class="col">
            <p id="text">Lorem ipsum dolor sit amet consectetur adipisicing elit. Corporis, fugiat.</p>
        </div>
        <script> 
            $(document).ready(function(){
                $('p').each(function() {
                    var words = $(this).text().split(' ');
                        for (i = 0; i < words.length; i++) {
                            if (i === 0) {
                                $("#text").html('<u>' + words[i] + '</u');
                            } else {
                                $("#text").append(' <u>' + words[i] + '</u>');
                            }
                        }   
                });
            });
        </script> 
    </body>
</html>
Write a jQuery code to underline all the words of a text. Write a jQuery code to underline all the words of a text. Reviewed by technical_saurabh on May 02, 2021 Rating: 5

No comments:

Powered by Blogger.