jquery Get Set Drop-down menu value, add drop-down menu element, empty dropdown box content

Source: Internet
Author: User

jquery Get Set Drop-down menu value, add drop-down menu element, empty dropdown box content
Remove the text of the selected item from the Pull menu

$ ("#select option[selected]"). Text ();//select and option have spaces, option is child element of select
$ ("#select option:selected"). Text ()//if written as $ ("#select"). Text () Select all Drop-down menu texts


2. Get and set the value of the Drop-down menu

$ ("#select"). Val ();//Fetch value
$ ("#select"). Val ("value");/setting, if there is an option in the select that has value, the option is selected, and if it does not exist, the select does not make any changes


3. Empty the Pull-down menu

$ ("#select"). empty ();
$ ("#select"). HTML ("");


4. Add elements to the following menu

$ (' <option value= "1" >1</option> "). Appendto ($ (" #select "));
$ ("#select"). Append (' <option value= ' 1 ">1</option> ');

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.