Knowledge Walls
Gopal Rao
Mumbai, Maharashtra, India
Passcode:
How to add html in jquery in Jquery functions of JQuery Examples
17578 Views
Example: 2 How to add html element in page
<html>

<head>
    <title>HTML-JQuery</title>
    <script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>

    <script type="text/javascript">
        $(function () {
            $(".defined").html('<div class="added">welcome</div>');
        });
    </script>
    <style type="text/css">
        .added {
            color: red;
        }
    </style>
</head>

<body>
    <div class="defined"></div>
</body>

</html>
Example: 1 Demo 
Note 
.html() function used to get an html element from html page.
Example: 1 How to get html element from page.

.html('<div>welcome</div>').
Example: 2 How to add html element in page.

Note:
If you use text() can't add the html tags in page.
Example: 1 How to get html element from page
<html>

<head>
    <title>HTML-JQuery</title>
    <script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>

    <script type="text/javascript">
        $(function () {
            alert($(".defined").html());
        });
    </script>
    <style type="text/css">
        .added {
            color: red;
        }
    </style>
</head>

<body>
    <div class="defined">
        <div class="html">hello welcome to This page.</div>
    </div>
</body>

</html>
Example: 2 Demo 
Next Topics
Next lessons of current book.
Best Lessons of "JQuery Examples"
Top lessons which are viewed more times.
  Copyright © 2014 Knowledge walls, All rights reserved
KnowledgeWalls
keep your tutorials and learnings with KnowledgeWalls. Don't lose your learnings hereafter. Save and revise it whenever required.
Click here for more details