jQuery Before and After


I am trying get pass this excerise and I don’t know what is wrong with the way I am writing this.

Prompt: Go ahead and add a <p> tag .after() the <div> with the ID #one. You can place any text you like in your <p> tag.

My Inputed Code:


Before and After
We can specify where in the DOM we insert an element with the .before() and .after() functions. The syntax looks like this:

$('target').after('<tag>To add</tag>');

Where ‘target’ is the element after which you want to add something and the bit between <tag>s is the HTML element you want to add. You can add <h1>s, <div>s, or any other valid HTML you like.


jquery code always required document.ready, like you learned


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.