The filtering operations in jquery are explained in detail

  • 2020-03-30 00:38:54
  • OfStack

1. The filter Filtering

The name of the instructions For example, Eq (index) Get the NTH element Gets the matched second element:
$(" p "). Eq. (1) The filter (expr)

Filters out the collection of elements that match the specified expression.

Reserve the element with the select class:
$(" p "). The filter (" selected ") The filter (fn)

Filters out the collection of elements that match the return value of the specified function

This function internally evaluates each object once (as '$.each'). If the called function returns false, the element is removed, otherwise it is retained.

Keep the elements without ol in the child elements:

$(" div "). The filter (function (index) {
  Return $("ol", this).size() == 0;

Is (expr)

Note: this function does not return a jQuery wrapper set but a Boolean value

Checks the currently selected collection of elements with an expression that returns true if at least one of the elements matches the given expression.

If no element matches, or the expression is invalid, it returns 'false'. 'filter' is actually calling this function internally, so the filter() function's old rules apply here.

Returns true because the parent of the input element is a form element:
= 'checkbox' $(" input [type] "). The parent () is (" form ") The map (the callback)

Converts a set of elements to another array (whether or not an array of elements)

You can use this function to create a list of values, attributes, CSS styles, or other special forms. This can all be easily set up using '$.map()'

Create a list of values for each input element in the form:

$(" p "). Append ($(" input "). The map (the function () {
  Return the $(this). Val ();
}). The get (). The join () ", ");

Not (expr) Deletes the element that matches the specified expression Remove the element with the ID of the select from the p element:
$(" p ".) not ($(" # selected ") [0])

Slice (start, end)

Select a subset that matches Select the first p element:
$(" p "). Slice (0, 1);

Related articles: