Why doesn\'
Above answers are great, but as jquery evolves.. so you can also do:
var myId = $("#test").prop("id");