What's wrong with this code?


#1


https://www.codecademy.com/courses/web-beginner-en-v6phg/0/2?curriculum_id=50a3fad8c7a770b5fd0007a1#

I have tried different ways of appending the paragraph but not working. Brought these errors.
Uncaught TypeError: "

I am a paragraph

".append is not a function
Oops, try again. It looks like you didn't add a

to the page. Check the Hint if you need help!

$(document).ready(
    function(){
        ("<p>I am a paragraph</p>").append(".app");
        }
    );

#also tried this:

$(document).ready(
    function(){
        ("<p>I am a paragraph</p>").appendTo("body");
        }
    );


#2

Hi ! remember the correct syntax !

For .append( )
ex: $(document).ready( function( ){
$(".info").append("<p>Stuff</p>");
});

For .appendTo( )

ex: $("<p>Stuff!</p>").appendTo('.info');

Now you have in the 1st code you tried, the order is wrong if you notice for .append( ) , first you need to fill in correctly $(' '), lets say what goes inside is what you re going to work on and then the message.

ex: $(' ').append('<p>stuff !</p>')

If you decide to use .appendTo( ), don't forget that you need the $ symbol !

ex: $(<p>Stuff !</p>).appendTo(' ');

Compare your code with this explanation, see whats missing and you will find the answer , if you still have trouble let me know! GL!

Happy Coding!


#3

Thanks. It worked:slight_smile:


#4

Glad to hear that !

Happy Coding !


#5

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.