How to remove div content using html() in jQuery or remove and add content to the div using jQuery html

  Uncategorized

 How to remove div content using html() in jQuery or remove and add content to the div using jQuery html

<html>
<head>
    <title></title>

    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>

    <script type="text/javascript">
        $(document).ready(function() {
        $('#btnChangetext').click(function() {
            //remove the div content
                $("#RemovingContent").children().remove();
                $("#RemovingContent").html("");
            //adding content to div
                $("#RemovingContent").html("<a href=www.sourcecodehub.com>www.sourcecodehub.com</a>");
                //you can also add one more div to #RemovingContent
                $("<div>hello</div>").appendTo($("#RemovingContent"));

            });
        });
    </script>

</head>
<body>
    <div id="RemovingContent">
        ASP.NET professional
    </div>
    <input type="button" value="Change div text" id="btnChangetext" />
</body>
</html>

43 thoughts on - How to remove div content using html() in jQuery or remove and add content to the div using jQuery html

LEAVE A COMMENT