0

I have just started learning jQuery. Meanwhile, I was exploring, I found out that only difference between append() and appendTo() is in the syntax. So, I was trying the following piece of code, wherein append() and prepend() works but not rest of the two

<html>
<head>
    <script src="jquery-3.2.1.js"></script>
</head>
<body style="font-family:Georgia">
    <script>
        $(document).ready(function () {
            $('#1').append(' Tutorial');
            $('#2').prepend('Tutorial ');
            $('Tutorial ').prependTo($('#3'));
            $(' Tutorial').appendTo($('#4'));
        });
    </script>
    <div id="1">JavaScript</div>
    <div id="2">jQuery</div>
    <div id="3">C#</div>
    <div id="4">ASP.NET</div>
</body>
</html>

Any help would be greatly appreciated.

Learner
  • 3
  • 2

1 Answers1

0
$('#1').append('Tutorial')

is not the same as

$('Tutorial').appendTo($('#1'))

The former appends a string to '#1'. But the later uses 'Tutorial' to construct a dom element and that doesn't work. Try:

$('<span>Tutorial</span>').appendTo($('#1'))
Haitao Li
  • 1,695
  • 16
  • 25