Some times we have to change the div content using JQuery. In this example, i am removing the "RemovingContent" div content and add the "www.aspnettutorialonline.blogspot.com/" link as output.Also we can add one more new div to removed content. This is also one of the best JQuery Interview Questions
At first run:
After click on button:
At first run:
After click on button:
<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">
I am Ranga Rajesh Kumar(ASP.NET professional)</div>
<input type="button" value="Change div text" id="btnChangetext" />
</body>
</html>

Post a Comment
Please give your valuable feedback on this post. You can submit any ASP.NET article here. We will post that article in this website by your name.