Home >Web Front-end >JS Tutorial >What are the basic filters for jquery
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.
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=$('<ul />').appendTo($('.logonav')); for(var i=0;i<_data.length;i++){ var fdata=_data[i]; var fil = $('<li>'+fdata.NAME+'</ul>').appendTo(fnav); fil.data("attr",fdata); fil.on("click",function(){ $(this).addClass('ztNav_cl').sublings().removeClass("ztNav_cl"); var data = $(this).data('attr'); var ext = parseExtext(data.EXTENSTIONS); if(ext!="" && ext!=null){ var func=eval(ext.func); if(typeof(func) == 'function'){ func?func(data):false; } } }); } //默认显示第一个li标签中的内容 $('.logonav ul li:first').addClass('ztNav_cl').sublings().removeClass("ztNav_cl"); var data = $(this).data('attr'); var ext = parseExtext(data.EXTENSTIONS); if(ext!="" && ext!=null){ var func=eval(ext.func); if(typeof(func) == 'function'){ 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!