Moving <p> and other HTML elements around


#1



4.Moving Elements Around, Modifying HTML Elements, JQuery.


I think I have followed all the steps but I keep this exercise wrong. I haven't learned it yet with the discussion forum, so I was looking for more help. Anybody that understands this better than me?


$(document).ready(function() {
    $("#one").after("<p>I'm the man</p>");
});

$("div").after($("#one"));

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


#2

HI try to put that

$("div").after($("#one"));

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

inside the

$(document).ready(function() {

});

#3

Or is this the right code?

$("<p>").after($("#one"));

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

#4

As in this?

$(document).ready(function() {
    $("#one").after("<p>I'm the man</p>");
    $("div").after($("#one"));
    $("#two").after($("<p>"));
});

#5

....................yes, Did it work?


#6

no :anguished:
i tried both of these but they didn't work:

$(document).ready(function() {
    $("#one").after("<p>I'm the man</p>");
    $("<p>").after($("#one"));
    $("<p>").after($("#two"));
});

and

$(document).ready(function() {
    $("#one").after("<p>I'm the man</p>");
    $("div").after($("#one"));
    $("#two").after($("<p>"));
});

#7

Here the instruction..

1 In script.js, add a new line below your code to move your <p> tag after the <div> with id #one
and you did it rigth

$(document).ready(function() {
    $("#one").after("<p>I'm the man</p>");
});

2-3 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

the seond instruction seems like it was asking you to create a new tag <div> but it's asking you to use the id #two so you should just have in your code

$(document).ready(function() {
    $("#one").after("<p>I'm the man</p>");
    $("#two").after($("p"));
});

and that should be

.after($("p"))

insead of

.after($("<p>"))

HOpe that could help you


#8

Thank you @wizmarco! Your explanation was detailed and really helped me understand. Hope this helps others too.