How to add text in p tag using jquery

How to add text in p tag using jquery


In this tutorial, you will be learning how to add a text in html p tag using jquery.

We are going to Set Content using jQuery text() method as given below example. 

Syntax:

$(selector).text( str )

Example:

<!DOCTYPE html>
<html lang="en">
<head>
    <title>How to add text in p tag using jquery</title>
</head>
<body>

    <div>
        <p id="myPara">  </p>

        <button type="button" id="myButton">Click to Add</button>
    </div>

    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script>
        $(document).ready(function () {

            $('#myButton').click(function (e) {
                e.preventDefault();

                var paragragh = "Hello, I am funda of web IT. We provide online web tutorials";

                $('#myPara').text(paragragh);

            });

        });
    </script>
</body>
</html>


Thanks for reading.

© Copyright - 2018 - 2022 | All rights reserved at Funda of Web IT