Moving Elements Around What did I do wrong?


#1

The question is:
In script.js, add a new line below your code to move your p tag after the div with id #one
create a new jQuery selector that targets the div with the id #two.
Using after again, select the p tag you created and move it after the div with id #two.

My answer:
$(document).ready(function(){
$('p').after($("#one"));
$('p').after($("#two"));
})

I feel like I couldn't understand the question @@


#2

I think you just have your statements in the wrong area.

Example 1:

$('p').after($(#two));

You're trying to say it like English saying "make 'p' after '#two'", but the way the code is being read is like this " '#two' is after 'p'" The parameter is the second parenthesis saying I want this thing AFTER the thing I'm attached to.

$("ThingNotMoving").after("ThingIWantToMove");

And seeing as you don't already have a

in the html section, you will either have to change that so there is a

there with words, OR you can do the following:

$("#two").after("<p>HI</p>");

I hope this helps explain things a little.


#3

Pretty close, @lolman.

$(document).ready(function(){
    $('#one').after('<p>Hello!</p>');
    $('#two').after($('p'));
});

We create a paragraph element in the form of an HTMLString which is inserted into the DOM immediately following <div id="one">Div #1</div>. Now that a paragraph node actually exists, we can target it with a jQuery P-node selector,

$('p')

and move it to follow <div id="two">Div #2</div>. That's it in a nutshell. The next lesson handles this differently, so for this one, keep it simple.


#4

I'm glad I wasn't the only one having problems understanding this question. It is incredibly unclear. Thanks, @mtf for the clarification.


#5

You're welcome, and free to check mark it if you believe it is the solution to the OP. Seekers are more likely to browse the marked solutions so they can move on.


#6

I do not understand that code

$(document).ready(function(){
  $('#one').after('<p>Hello!</p>');
  $('#two').after($('p'));
});

is not correct?


#8