van
van

Reputation: 9449

Get element by title jQuery

I have searched but cannot find the jQuery selector that gets an element by a title. So I would be trying to get a handle on the dropdown with title =='cars'

Eg:

<select title='cars'>
  <option value="volvo">Volvo</option>
  <option value="saab">Saab</option>
  <option value="mercedes">Mercedes</option>
  <option value="audi">Audi</option>
</select>

Thanks alot,

Upvotes: 37

Views: 106571

Answers (2)

Vibhor Dube
Vibhor Dube

Reputation: 5053

While Nick's answer solves the problem for many, it didn't for me due to a simple reason of it being case-sensitive.

Appending the attribute value with i would make it case-insensitive. Try this:

$("select[title='cars' i]")

This would also work in case your title is dynamic and might come with a capital case as Cars rather than static cars.

Reference for case insensitivity flag i: https://stackoverflow.com/a/38923109/4365626

Upvotes: -1

Nick Craver
Nick Craver

Reputation: 630389

Use the attribute-equals selector, like this:

$("select[title='cars']")

There are other attribute selectors available as well if the need arises :)

Upvotes: 99

Related Questions