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
$(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
$(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 secondelement (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 allelements 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 allelements without the class name "intro":
$(document).ready(function(){ $("p").not(".intro"); });
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!