LearnFast.Ninja

jQuery append

The main idea: $("#" + Id).append(text); create custom element, create javascript function, call it append_html.

Step 1: create custom element

<div id="Div_ID" onclick="append_html('Div_ID', 'appended html')">

    jQuery append html

</div>


Step 2: create javascript function, call it append_html

function append_html(Id, text) {

    $("#" + Id).append(text);

}


The main idea:

$("#" + Id).append(text);


Complete code:

<html>

<head>

    <title>jQuery change ID </title>

    <script type="text/javascript" src="http://code.jquery.com/jquery-1.4.4.min.js"></script>

    <script type="text/javascript" src="http://remysharp.com/downloads/jquery.marquee.js"></script>

    <script type="text/javascript">

        function append_html(Id, text) {

            $("#" + Id).append(text);

        }

    </script>

</head>

<body>

    <div id="Div_ID" onclick="append_html('Div_ID', 'appended html')">

        jQuery append html

    </div>

</body>

</html>


Result:



Tags

jquery

jquery-tutorial-for-beginners