How does jQuery obtain all values of the same class label (which cannot be obtained by default) _ jquery

Source: Internet
Author: User
JQuery always returns the value of the first class label, so it cannot meet our requirements. How does jQuery obtain all the values of the same class label, I will share with you the following method. This problem occurs during development. Because jQuery always returns only the value of the first class label, it cannot meet our requirements.

For example:

The Code is as follows:


Var btn = jQuery ('. btn'). val ();


Only the value of the html element whose first class label is btn is obtained.

Obtain the values of all html elements of a group of class tags. You have to use jQuery's each traversal.

The Code is as follows:


Var btns = new Array (); // You can also specify var btns = [];

JQuery ('. btn'). each (function (key, value ){

Btns [key] = $ (this). val ();

// Or you can write it like this:

// Btns [key] = $ (value). val ();
});

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.