Get element by title jQuery

2019-01-11 07:07发布

问题:

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,

回答1:

Use the attribute-equals selector, like this:

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

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