How to append Anchor tag to HTML Body Dynamically using jquery


Using JQuery we can add anchor tag to body very easily. This can be possible by the AppendTo JQuery Method.

In the below example, i am appending anchor tag to body using jquery. We can also append div to any class or div using this Jquery AppendTo Keyword.

MainCode:


$('<a href="http://jqueryexamplecode.blogspot.com">JQueryExampleCode.blogspot.com</a>').appendTo('body');


Complete Code:

<html>
<head>
    <title></title>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
</head>
<body>

<div id='NewContent' style="color:Green"></div>
<script type="text/javascript">
    $('<a href="http://jqueryexamplecode.blogspot.com">JQueryExampleCode.blogspot.com</a>').appendTo('body');

   
</script>
</body>
</html>


Output:
How to append Anchor tag to HTML Body Dynamically using jquery
How to append Anchor tag to HTML Body Dynamically using jquery

Post a Comment