jQuery 选择器: 允许我们选择和操作 HTML 元素。它用于使用 jQuery 选择器选择 HTML 元素,例如 id、类、类型、属性等,然后将任何 CSS 属性或事件添加到选定的 HTML 元素。
语法:选择按钮标签的语法是
$("button")
例子:
HTML
Using jQuery Filter
HTML
Jquery Filter
My name is Donald.
Geeks
SkeeG
For
roF
Geeks
输出:单击该按钮后,我们将在标题上看到一个红色边框。
jQuery 过滤器:此方法用于指定 HTML 元素的条件。 Filter() 方法返回符合特定条件的元素。
句法:
$(selector).filter(criteria, function(index))
例子:
HTML
Jquery Filter
My name is Donald.
Geeks
SkeeG
For
roF
Geeks
输出:过滤器搜索活动类标签并为它们着色。
jQuery 中 selector 和 filter() 的主要区别:
Selector in jQuery | filter() n jQuery |
---|---|
jQuery selector selects all elements based on the elements name given by you. | jQuery filter( ) adds further detail to the selected elements by specifying the criteria of selection. |
It works independently of filter( ), which means there is no need to use it along with the filter( ) method. | It works along with the selector. By combining filters with your selectors, we can work to much high degree of precision. |
Syntax to use it is as follows: $(“button”) selects all buttons of the HTML page. |
Syntax to use it as follows: $(button).filter(criteria, function(index)) selects buttons having criteria and applies function on it. |