Why doesn\'
This is an old question, but as of 2015 this may actually work:
$('#test').id;
And you can also make assignments:
$('#test').id = "abc";
As long as you define the following JQuery plugin:
Object.defineProperty($.fn, 'id', {
get: function () { return this.attr("id"); },
set: function (newValue) { this.attr("id", newValue); }
});
Interestingly, if element
is a DOM element, then:
element.id === $(element).id; // Is true!