Removing Elements: "Make sure you remove your <p> using the .remove() function."


#1



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


Error: Make sure you remove your p using the .remove() function.

The code actually works. It removed the $p. I have no idea why this error message appeared.


$(document).ready(function() {
    var $p = $('<p>Lights will guuuuiiiiide you home. And igniiiiite your bones.</p>');     
    $('#two').after($p);
    $($p).remove();
});


#2

So instead of using this code:

$($p).remove();

I used:

$('p').remove();

And it worked.

Can someone please explain to me why using the variable $p did not work?


#3

@trishajeane

why using the variable $p did not work?

$p is an HTML element. $('p') is an HTML selector. If you want to remove an element, you have to use a selector, and $p is for when you want to add an element :slight_smile:

Does that help any?


#4

A post was split to a new topic: 5.Removing elements