Development/jQuery

jquery - 메소드 정리

linuxism 2012. 11. 1. 13:30


- get

Definition and Usage

The get() method gets the DOM elements specified by the selector.

Syntax

$(selector).get(index)

ParameterDescription
indexOptional. Specifies which of the matching elements to get (by index number)


출처 - http://www.w3schools.com/jquery/misc_get.asp



- map

Description: Translate all items in an array or object to new array of items.

  • version added: 1.0jQuery.map( array, callback(elementOfArray, indexInArray) )

    arrayThe Array to translate.

    callback(elementOfArray, indexInArray)The function to process each item against. The first argument to the function is the array item, the second argument is the index in array The function can return any value. Within the function, this refers to the global (window) object.

  • version added: 1.6jQuery.map( arrayOrObject, callback( value, indexOrKey ) )

    arrayOrObjectThe Array or Object to translate.

    callback( value, indexOrKey )The function to process each item against. The first argument to the function is the value; the second argument is the index or key of the array or object property. The function can return any value to add to the array. A returned array will be flattened into the resulting array. Within the function, this refers to the global (window) object.

The $.map() method applies a function to each item in an array or object and maps the results into a new array. Prior to jQuery 1.6$.map() supports traversing arrays onlyAs of jQuery 1.6 it also traverses objects.

Array-like objects — those with a .length property and a value on the .length - 1 index — must be converted to actual arrays before being passed to $.map(). The jQuery library provides $.makeArray() for such conversions.

// The following object masquerades as an array.
var fakeArray = {"length": 1, 0: "Addy", 1: "Subtracty"};

// Therefore, convert it to a real array
var realArray = $.makeArray( fakeArray )

// Now it can be used reliably with $.map()
$
.map( realArray, function(val, i) {
 
// do something
});

The translation function that is provided to this method is called for each top-level element in the array or object and is passed two arguments: The element's value and its index or key within the array or object.

The function can return:

  • the translated value, which will be mapped to the resulting array
  • null or undefined, to remove the item
  • an array of values, which will be flattened into the full array


출처 - http://api.jquery.com/jQuery.map/