.map()
JQ Home <<
Filtering <<
.map()
Filter elements.
Description
The .map() method is used to pass each element within the current matched set through a function, producing a new jQuery object containing returned values.
Syntax
| Signature | Description |
|---|---|
.map( callback(index, domElement) ) | Pass each element within the current matched set through a function, producing a new jQuery object containing returned values. |
Parameters
| Parameter | Description | Type |
|---|---|---|
callback(index, domElement) | A function.
| Function |
Return
A jQuery object containing the filtered elements.
.map( callback(index, domElement) ) Example Filtering << Top
Pass each element within the current matched set through a function, producing a new jQuery object containing returned values.
In the example we add to the paragraph below each checkbox value that is checked.
$(function(){
$('#btn5').on('click', function() {
$("#yourpies").append( $("#form1 input[type='checkbox']").map(function(){
if ($(this).is(":checked")) {
return $(this).val();
}
}).get()
.join(", ") );
});
});
You like:
Related Tutorials
jQuery Intermediate Tutorials - Lesson 1 - Filtering Elements
