Is
$(this).attr(\'id\')
the same as:
this.id
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')
.
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
.
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.