Output is not coming while using addClass method

Output is not coming while using addClass method

Hi

Here is the jquery code :

<html>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<body>
<script>

$(document).ready(function(){
$( "<div></div>" ).after( "<p>Exception</p>" ).addClass( "foo" );
console.log($("p.foo").get(0).innerHTML);
});



</script>
<div> Hello</div>
<p id = "world"> World</p>
</body>
</html>

Behaviour should be like this :

<div class = "foo">Hello</div>
<p class = "foo">Exception</p>-------------------------------------------------->line has been added through javascipt
<p id = "world">World</p>

output : I am getting error at this line :
                               console.log($("p.foo").get(0).innerHTML);

Output Should come :

Exception

Another Query :  class = "foo" will come in both "div" and "p" or only in "p"

Regards & Thanks
Varun