UncleCoder.com

UncleCoder.com

Free programming examples and instructions

jQuery append() to p tag

Demo and Code for how to add html tags in P tag using jQuery append() method.

by Athil


Posted on 22 Jun 2019 Category: jQuery Views: 1857


Here I am going to show how to add HTML tags to a P tag using jQuery append() method.

DEMO

append() with control ID

  $("#Myp").append("<b>My new text</b>");

Where "Myp"  is the id of p tag, Well it starts with a (#) Hash, if we are using control id and <b>My new text<b> is the HTML tag will append there on the p tag.

append() with Class Name 

  $(".classname").append("<b>My new text</b>");

Where "classname" is the name of the class of control, Well it starts with a .(Dot) , if we are using class name and <b>My new text<b> is the HTML tag will append there on the p tag.

Full Demo Code

?<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Demo for jQuery append to p tag</title>
       <script type="text/javascript" src="js/jquery.min.js" ></script>
    
</head>
<body>
    <h1>Demo for jQuery append to p tag </h1>

    <p id="Myp">my paragraph</p>
    <button id="btnAppend" type="submit">Append to p</button>
    <script>

        $("#btnAppend").click(
        function () {
            $("#Myp").append("<b>My new text</b>");
        });
        </script>

</body>
</html>

 



Leave a Comment:


Click here to register

Popular articles