Cybercrux

Everything is achievable through technology

select

jQuery – Select element cheat sheet

Note: elementid refers to the actual id of the select element. elementname refers to the actual name
of the select element.
e.g.

Selecting an element(s) for further information refer to jQuery API Selectors

Basics:
Select element by id $(“#elementid”)
Select all select elements $(“select”)
Select all select elements by class $(“select.classname”)

Hierarchy:
Select all options from a select element $(“#elementid option”)

Basic Filters:
Select the first option $(“#elementid option:first”)
Select the last option $(“#elementid option:last”)
Select the option at a particular index (variant 1) $(“#elementid option:eq(2)”)

Attribute Filters:
Select all options that have a value attribute set $(“#elementid option[value]”)
Select element by name $(“select[name=elementname]”)

Form Filters:
Select the selected option $(“#elementid option:selected”)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s