jQuery: what about this.title?

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');

Related posts:

  1. jQuery: Setting Up a Vector Path Fill Color
  2. Quick Look at JavaScript Objects
  3. jQuery Get the Id of the Current Element
This entry was posted in javascript, micro tutorial and tagged , , , , , , . Bookmark the permalink.

One Response to jQuery: what about this.title?

  1. 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.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">