jQuery Before and After


#1

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:

$('#one').after('<p>Test</p>');

Section
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.


#2

jquery code always required document.ready, like you learned


#3

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