Take the 2-minute tour ×



the same as:

share|improve this question
add comment

4 Answers

up vote 13 down vote accepted

No, they're not exactly the same.

They'll both return the element's ID, but if the element has no ID, then this.id will return a blank string while $(this).attr("id") will return undefined.

share|improve this answer
add comment

Almost (see Jeff's answer).

jQuery abstracts away attribute getting, but it isn't always the most terse option.

It is however shorter than getAttribute('id').

share|improve this answer
add comment

Same result, but this.id is much faster as it doesn't require all the jQuery stuff around it. You will also get different results if that item doesn't have an id.

share|improve this answer
add comment

Exactly the same, it'll get the element's ID... honestly don't know what more I can say here for a more in-depth answer.

share|improve this answer
Thanks thedixon! I appreciate you trying to help out. Q: How are you monitoring jQuery questions? Is it through email or some other method? The reason why I ask is because I currently don't monitor any tags but have been thinking about doing so. –  Phillip Apr 8 '11 at 15:52
Hi there - I currently monitor tags by adding to my favorite tags and then just refreshing the newest questions ever now and again, the jQuery ones pop up in orange so are easy to spot :) –  Chris Dixon Apr 8 '11 at 15:59
They aren't exactly the same, see Jeff's answer for why. –  Bala Clark Jan 23 '13 at 10:27
add comment

Your Answer


