Home >Web Front-end >JS Tutorial >What are the basic filters for jquery

What are the basic filters for jquery

藏色散人
藏色散人Original
2020-11-16 10:57:532928browse

jquery basic filters include: 1. jQuery first method, which returns the first element of the selected element; 2. jQuery last method, which returns the element with the specified index number among the selected elements; 3 , jQuery eq method, this method returns the element with the specified index number among the selected elements, etc.

What are the basic filters for jquery

Recommended: "js video tutorial"

jQuery basic filter

Recently, the editor is learning the knowledge of jQuery and summarizes the knowledge recently used in the project.

jQuery first() method

The first() method returns the first element of the selected element.

The following example selects the first 25edfb22a4f469ecb59f1190150159c6 element inside the first ff6d136ddc5fdfeffaf53ff6ee95f185 element:

$(document).ready(function(){
  $("ul li").first();
});

jQuery last() method

last() method returns the last element of the selected elements.

The following example selects the last 25edfb22a4f469ecb59f1190150159c6 element in the last ff6d136ddc5fdfeffaf53ff6ee95f185 element:

$(document).ready(function(){
  $("ul li").last();
});

jQuery eq() method

## The #eq() method returns the element with the specified index number among the selected elements.

The index number starts from 0, so the index number of the first element is 0 instead of 1. The following example selects the second e388a4556c0f65e1904146cc1a846bee element (index 1):

$(document).ready(function(){
  $("p").eq(1);
});

jQuery filter() method The

filter() method allows you to specify a standard. Elements that do not match this criterion are removed from the collection, and matching elements are returned.

The following example returns all e388a4556c0f65e1904146cc1a846bee elements with the class name "intro":

$(document).ready(function(){
  $("p").filter(".intro");
});

jQuery not() method

not () method returns all elements that do not match the criteria.

Tip: The not() method is the opposite of filter().

The following example returns all e388a4556c0f65e1904146cc1a846bee elements without the class name "intro":

$(document).ready(function(){
  $("p").not(".intro");
});

[Example]

When dynamically generated on your page When the menu (li tag) needs to display the first menu function by default, the .first method is very useful.

function createDiv(obj){
var pathName = window.localtion.pathname;
var curfilepath = (pathName).substring(pathName.substring(1).indexOf('/')+1);
//把数据转换成树形结构
var _data = transform2NormalData(obj);
if(_data.length>0){
var fnav=$(&#39;<ul />&#39;).appendTo($(&#39;.logonav&#39;));
for(var i=0;i<_data.length;i++){
var fdata=_data[i];
var fil = $(&#39;<li>&#39;+fdata.NAME+&#39;</ul>&#39;).appendTo(fnav);
fil.data("attr",fdata);
fil.on("click",function(){
$(this).addClass(&#39;ztNav_cl&#39;).sublings().removeClass("ztNav_cl");
var data = $(this).data(&#39;attr&#39;);
var ext = parseExtext(data.EXTENSTIONS);
if(ext!="" && ext!=null){
var func=eval(ext.func);
if(typeof(func) == &#39;function&#39;){
func?func(data):false;
}
}
});
}
 
//默认显示第一个li标签中的内容
$(&#39;.logonav ul li:first&#39;).addClass(&#39;ztNav_cl&#39;).sublings().removeClass("ztNav_cl");
var data = $(this).data(&#39;attr&#39;);
var ext = parseExtext(data.EXTENSTIONS);
if(ext!="" && ext!=null){
var func=eval(ext.func);
if(typeof(func) == &#39;function&#39;){
func?func(data):false;
}
}
}
}

The above is the detailed content of What are the basic filters for jquery. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:Why use jqueryNext article:Why use jquery