Removing elements

jquery

#1
I can't get my code to remove my paragraph..

var $paragraph = $("p");

$("div").after($paragraph);
$("div").after($("p"));

$('p').remove();

#2

The above is an empty collection. Try adding this line right after it...

    $('#one').after('<p>length of $paragraph = ' + $paragraph.length + '</p>');
    $('#two').after($('p'));
    // $('p').remove();

Output

        Greetings
        Div #1
        Div #2
        length of $paragraph = 0

Why will it be empty? Because there are no paragraph elements in the HTML document at load time. We need to create a paragraph in the first line, then go from there now that it can be selected.