5. Removing elements. Removed from HTML viewer but still get error



Get this: Oops, try again.
Make sure you remove your < p > using the .remove() function.

Why doesn't it pass when I call it on $p ? What's different?

Sorry, my goal is to get a solid understanding of all of this and not just keep passing level after level.

    $("#one").after("<p>Test Test</p>");
    var $p = $("p");


Hi you should remove your element like that

$('element to remove').remove();


Is that because that's the "right" way to pass this step?

I'm only a bit confused because the "p" element does get removed from the html viewer when you hit full screen. So is it "technically" correct the way I did? But just codecadamy doesn't accept that as an answer?

Or do I have it completely wrong here?


I think that when you do that


you are removing the variable var $p = $("p"); which make the same effect as removing the tag but the lesson want you to remove the tag so you should use the one I gave you.


What I fail to understand is why this needs to be part of the function, surely this can also be a stand-alone line on text, in the real world, if something needs to be removed it is never normally directly after the creation of it?

my code:

$(document).ready(function() {
    $('#one').after("<p>This is mine</p>");

//var $paragraph = $("p");


(I have corrected it to move forward but I am not sure I learnt anything)


@snox2014 That won't work; you're removing all <p> elements with your last line before you ever add any, on your second line.

In the real world, either the <script> tags go in the bottom of the HTML document, or everything goes inside the $(document).ready(...); function or some equivalent of it.