Question on Before and After; #one just for <div>'s


Quote the lesson:
"Go ahead and add a p> tag .after() the div> with the ID #one"

My code is:

$('#one').after('<p>Hey, imma paragraph</p>');

How would I go about getting '#one' just for divs? What could I do if there was a #one for a p>? Or would this not be a problem.

Thanks for your help =D


Hi Thecoderekker,

You can add an element name before a class or id. like this:


and that would do what you want. But there's a problem, which is that ids never get shared. An element's id is unique to that element and may not be used anywhere else on the page. There are reasons for this, such as the ability to link to a specific area on a page.
So if you want multiple elements to share one thing, use a class instead of an id :slightly_smiling:

<!-- this is ok: --> 
<div class="example"></div>
<div class="example"></div>

<!-- this is *NOT* ok: --> 
<div id="example"></div>
<div id="example"></div>


Cool! Thanks for your help.