In my last post I was talking about the short way to access the id attribute:
this.id; this.attr('id'); // this is the same but slower |
Beside the most important thing that this is the slower notation, you get also larger notation, which in JavaScript is really pain.
What’s interesting is that you can access almost every attribute of an element with that notation. Take a look at the following example:
<img src="image.jpg" title="test" /> |
and than
$('element').title |
This is much faster and quite nice in place of
$('element').attr('title'); |
Sorry – if $(‘element’) refers to a jQuery selector, then this code is faulty.
You’d need to refer to $(‘element’)[N].title where N is the item in the selector’s collection.