Add, delete, and value option in jquery

Source: Internet
Author: User

jquery Gets the text and value selected by select:


1. $ ("#select_id"). Change (function () {//code ...}); Adds an event for a select that fires when one of the items is selected

2. Var checktext=$ ("#select_id"). Find ("option:selected"). Text (); Gets the text selected by select

3. Var checkvalue=$ ("#select_id"). Val (); Gets the value of the Select selection

4. Var checkindex=$ ("#select_id"). Get (0). SelectedIndex; Get the index value selected by select

5. Var maxindex=$ ("#select_id option:last"). attr ("index"); Get the maximum index value for select

jquery Add/Remove option items for select:

1. $ ("#select_id"). Append ("<option value= ' value ' >Text</option>"); Append an option to select (dropdown)

2. $ ("#select_id"). Prepend ("<option value= ' 0 ' > Please select </option>"); Inserts an option for the Select (first position)

3. $ ("#select_id option:last"). Remove (); Delete index value maximum option (last) in select

4. $ ("#select_id option[index= ' 0 ']"). Remove (); Delete option with index value of 0 in select (first)

5. $ ("#select_id option[value= ' 3 ']"). Remove (); Delete option value= ' 3 ' in select

5. $ ("#select_id option[text= ' 4 ']"). Remove (); Delete option text= ' 4 ' in select

Empty content:

$ ("#charCity"). empty ();

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.