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

What are the basic filters for jquery

藏色散人
Release: 2020-11-16 10:57:53
Original
2929 people have browsed it

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

  • element inside the first
      element:

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

      jQuery last() method

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

      The following example selects the last

    • element in the last
        element:

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

        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

        element (index 1):

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

        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

        elements with the class name "intro":

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

        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

        elements without the class name "intro":

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

        [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;
        }
        }
        }
        }
        Copy after login

        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!

  • Related labels:
    source:php.cn
    Statement of this Website
    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
    Popular Tutorials
    More>
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template