Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery $("#content").append not working

I'm trying to learn JQuery, but not doing well. Currently, I'm trying to learn how to use .append to have Ajax functionality which allows one to view new dynamic content without reloading. When I try the following, however, nothing occurs.

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
    <head>
        <title>JQuery Test</title>
        <script src="http://code.jquery.com/jquery-2.0.3.min.js"></script>
    </head>
    <body>
        <div id="content"/>
        <script type="text/javascript">
function callback() {
    $("#content").append($("qwerty"));
};
$(document).ready(function() {
    //window.setTimeout(callback, 100);
    callback();
});
        </script>
    </body>
</html>

To the best of my knowledge, this should make "qwerty" appear as if I has simply done <div id="content">qwerty</div>, but instead I get a blank page. If I replace the .append call with alert("qwerty"), it is properly displayed. What am I doing wrong?

like image 311
Nathan Ringo Avatar asked Dec 08 '13 05:12

Nathan Ringo


2 Answers

$("#content").append("qwerty").

Just remove $ simple in your coding.. if you want to append text, you can directly pass the text in double quotation

like image 87
Haji Avatar answered Sep 22 '22 04:09

Haji


You are trying to find an element with tagname qwerty in the dom like <qwerty>sometext</qwerty> and append it to #content.

To append the string qwerty to #content use

$("#content").append("qwerty");

Demo: Fiddle

like image 34
Arun P Johny Avatar answered Sep 22 '22 04:09

Arun P Johny