How can I select using jQuery dropdown options that only contain a specific attribute?

I have a dropdown list where only some of the options have a certain attribute. For example

<select id="dropdown">
<option value="v1" data-otherattribute="12345">line 1</option>
<option value="v2" >line 2</option>
<option value="v3" data-otherattribute="67890">line 3</option>
<option value="v4" >line 4</option>
<option value="v5" data-otherattribute="234567">line 5</option>

Open in new window

What is the jQuery to return just items v1, v3 and v5 - i.e. just the lines with the data-otherattribute setting?

For example, I think I could get them by searching by value like this
        var option = dropdown.find("option[value^='V1'],option[value^='V3'],option[value^='V5'])";

Open in new window

but in reality I don't know what the values will be, I need to find just those with the attribute set. Also note the actual value of the attribute itself will change, so I can't search by that.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Julian HansenCommented:
You can use the hasattribute
var opts = $('#dropdown option[data-otherattribute]');

Open in new window

purplesoupProgrammerAuthor Commented:
Thanks - I'm just leaving off, I'll give it a go tomorrow...
Julian HansenCommented:
Here is a sample that demonstrates the concept and how to access the elements.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.