Why doesn\'
$('#test').attr('id') In your example:
$('#test').attr('id')
$(document).ready(function() { alert($('#test').attr('id')); });