Sunday, October 19, 2014

How to remove div content using html() in JQuery

How to remove div content using html() in JQuery


$("#RemovingContent").children().remove();
$("#RemovingContent").html("");


RemovingContent is the div that you want to remove content of :) 


here is the complete example

<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.aspnettutorialonline.blogspot.com>www.aspnettutorialonline.blogspot.com/</a>");
                //you can also add one more div to #RemovingContent
                $("<div>hello</div>").appendTo($("#RemovingContent"));
                
            });
        });
    </script>

</head>
<body>
    <div id="RemovingContent">
        it will be removed </div>
    <input type="button" value="Change div text" id="btnChangetext" />
</body>
</html>


0 comments:

Post a Comment