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


#1

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

My code is:

$(document).ready(function(){
$('#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


#2

Hi Thecoderekker,

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

$('div#one')

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>

#3

Cool! Thanks for your help.