jquery map calls the Get () method confused

Source: Internet
Author: User

$ ("P"). Append ($ ("input"). Map (function () {return $ (this). Val (); }). Get (). Join (","));
<form> <input type= "text" name= "name" value= "John" > <input type= "text" name= "password" value= "password" > <input type= "text" name= "url" value= "http://ejohn.org/" ></form>

This is a example I took from the official website.

I was very confused, do not understand why in the map method is called after a get method. In theory, the data returned by map should be an array (collection). You can directly call the Join method to convert to string.


Read the documentation carefully and find articles here.


I originally confused the JavaScript object/array (actually DOM) and Jqeruy Object/array these two concepts

In fact, JavaScript objects and arrays are not mutually identifiable with jquery.

When I found out about this "secret", I figured out why I needed the Get method.


. Get (): Retrieve the DOM elements matched by the JQuery object.

This is the definition of the official website. is to convert the jquery object to a DOM object. All DOM objects can be used by JavaScript. Here jquery is actually a smooth transition through the get mechanism.


So let's look back at the example above

Map returns the jquery array and then passes the get method to the JavaScript Dom array. The last call to the Join method becomes a string.


This article is from the "Development" blog, make sure to keep this source http://jamesdev.blog.51cto.com/2066624/1774930

jquery map calls the Get () method confused

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.