How can I select the 'title' attribute in an input tag in jquery?


I know this is an old post but here is your solution.

The var method can be very handy but you can do this directly via jQuery without var.

Say if you had a p (paragraph) with an id="p-2" and the title attribute value is RS4, and you like to colorize that paragraph in blue. You use the following.

$("#p-2[title='RS4']" ).css("color", "blue");

Another method if the title attribute value has the word RS4 contained in it in the case title="Audi RS4 is fast", then you can use ~= method.

$("#p-2[title~='RS4']" ).css("color", "blue");

Hope this helps


@Alex is partially correct, you can have numbers but the id just cannot start with a number.

in your case you would selected the input like this.