Edit in JSFiddle

var result = $('p').attr('id');
$("#output").text("p要素のIDは" + result + "です。");

<p id="greeting">こんにちは</p>
<div id="output"></div>
body{background-color:#f0f0e8;}
p{background-color:#65c59f}